Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reset array in multiview iphone app
    primarykey
    data
    text
    <p>I am trying to have a tableview that leads to another tableview whose list items depend on the first view. I have the database set up properly and my problem is that when I select one item on the first page and go to the second view for the first time it works fine but when I return to the first page and go back to the second view again the list still has the old values loaded with new ones. Is there a way to destroy the array and recreate it every time the second view is loaded? Where would I do this?</p> <p>Here is where my array is initialized in the delegate:</p> <pre><code> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self copyDatabaseIfNeeded]; organArray = [[NSMutableArray alloc] init]; procedureArray = [[NSMutableArray alloc] init]; [Organ getInitialDataToDisplay:[self getDBPath]]; [window addSubview:navigationController.view]; [window makeKeyAndVisible]; return YES; } </code></pre> <p>Here is where the data is added to the array in my custom class:</p> <pre><code> + (void) getDatabase:(NSString *)dbPath WithOrganID:(NSNumber *)organID { RadiologyAppAppDelegate *appDelegate = (RadiologyAppAppDelegate *)[[UIApplication sharedApplication] delegate]; if(sqlite3_open([dbPath UTF8String],&amp;database) == SQLITE_OK){ const char *sql = "select * from Organ"; sqlite3_stmt *selectstmt; if(sqlite3_prepare_v2(database, sql, -1, &amp;selectstmt, NULL) == SQLITE_OK){ while (sqlite3_step(selectstmt) == SQLITE_ROW) { NSInteger primaryKey = sqlite3_column_int(selectstmt, 0); Procedure *procedureObj = [[Procedure alloc] initWithPrimaryKey:primaryKey]; procedureObj.procedureName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,1)]; procedureObj.procedureID = sqlite3_column_int(selectstmt,0); [appDelegate.procedureArray addObject: procedureObj]; [procedureObj release]; } } } else sqlite3_close(database); } </code></pre> <p>Finally, here is my view controller:</p> <pre><code> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } Procedure *procedureObj = [appDelegate.procedureArray objectAtIndex:indexPath.row]; PVCprocedureObj = appDelegate.procedureArray; cell.textLabel.text = procedureObj.procedureName; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } </code></pre> <p>Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload