I have one ViewController containing two TableViews as shown below.
So the top table (firstTable) currently has two records. And I want to populate the bottom table (secondTable) with a different set of data (data2) according to the selection at the top, which, in fact, happens in many of my Windows applications.
Initially, I wondered how I could have one viewcontroller as the data source host two tables? And vikingosegundo explains how in this topic. Great, I've got that part taken care of. Now, I have the following code from Manage1ViewController.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// From Manage1ViewController.m for firstTable
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
NSString *name0 = cell.textLabel.text;
NSString *tsecs0 = [self findTsecs:name0];
[self openCreateDB2];
NSMutableArray *items2;
items2 = [[NSMutableArray alloc] init];
NSString *sql = [NSString stringWithFormat:@"Select * From data2 WHERE tsec = '%i'", [tsecs0 integerValue]];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(connection2, [sql UTF8String], -1, &statement, Nil)==SQLITE_OK){
while (sqlite3_step(statement)==SQLITE_ROW) {
char *field1 = (char *) sqlite3_column_text(statement, 1);
NSString *field1Str = [[NSString alloc]initWithUTF8String:field1];
NSString *str1 = [[NSString alloc]initWithFormat:@"%@", field1Str];
[items2 addObject:str1];
}
sqlite3_finalize(statement);
sqlite3_close(connection2);
}
/* Start populating secondTable with items2
*/
}
So far, so good... And the application has data (items2) according to user's selection on firstTable that needs to be populated into secondTable. But how?
After reading several dozen topics here and there, I've learnt that there are a couple of ways by which you can pass data. Well, in this case, I can't use segue since I'm passing data within the same view control. Anyway, it seems that some people here suggest that I do it either with Delegate and NSNotification. And it looks like using a delegate is appropriate in my case. Again, how? Is it the same idea with use of a popover window where I think I've used a delegate?
I appreciate your advice.