Hi all,
I have two UIViewControllers inside a navigation interface. The first one has a UITableView inside it (The view controller itself is both datasource and delegate). When one particular row is touched, the navigation view pushes the second view into the stack. This second view presents another UITableView with some options.
When one option is selected in the second view controller, the navigation pops the second view controller out of the navigation stack, but not before setting a property in the first navigation item that will be displayed in another section of the table View in the first. The second view controller also calls the reloadData on the first view controller's table view before popping. The problem, however, is that the first view controller's data is never refreshed.
Here is what happens on the second view controller when an item is tapped:
By debugging I discovered that, indeed, the activeScheme property has a value after this method call runs, so the line before the call to reloadData runs successfully. However, calling reloadData here does nothing. I even set up a breakpoint in the first view controller's cellForRowAtIndexPath: method, and the app never stopped on it.
As an alternative approach, I tried to call the reloadData method on the first view's viewWillAppear: method. Nothing happened.
I also tried using a CADisplayLink to call the reloadData method after popping the second view, and it still doesn't work.
I know I have my tableview set up correctly since it initially shows what it's supposed to. I just don't know why it won't refresh afterwards. Here is the code for the cellForRowAtIndexPath: method:
I have two UIViewControllers inside a navigation interface. The first one has a UITableView inside it (The view controller itself is both datasource and delegate). When one particular row is touched, the navigation view pushes the second view into the stack. This second view presents another UITableView with some options.
When one option is selected in the second view controller, the navigation pops the second view controller out of the navigation stack, but not before setting a property in the first navigation item that will be displayed in another section of the table View in the first. The second view controller also calls the reloadData on the first view controller's table view before popping. The problem, however, is that the first view controller's data is never refreshed.
Here is what happens on the second view controller when an item is tapped:
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.action ==@"set_active") {
FirstViewController *firstMenu = (FirstViewController*) [self.navigationController.viewControllers objectAtIndex:[self.navigationController.viewControllers count]-2];
Scheme* selectedScheme = [self.theSchemes objectAtIndex:indexPath.row];
firstMenu.activeScheme = selectedScheme;
[firstMenu.tableView reloadData]; //this method doesn't seem to work
[self.navigationController popViewControllerAnimated:YES];
}
By debugging I discovered that, indeed, the activeScheme property has a value after this method call runs, so the line before the call to reloadData runs successfully. However, calling reloadData here does nothing. I even set up a breakpoint in the first view controller's cellForRowAtIndexPath: method, and the app never stopped on it.
As an alternative approach, I tried to call the reloadData method on the first view's viewWillAppear: method. Nothing happened.
I also tried using a CADisplayLink to call the reloadData method after popping the second view, and it still doesn't work.
I know I have my tableview set up correctly since it initially shows what it's supposed to. I just don't know why it won't refresh afterwards. Here is the code for the cellForRowAtIndexPath: method:
Code:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.identifier){
self.identifier = [NSString stringWithFormat:@"MyIdentifier"];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.identifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:self.identifier];
}
if (indexPath.section ==0)
{
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [taskOptions objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text = self.activeScheme.name ; //this is the cell where the selected value is supposed to appear
}
return cell;
}
Last edited: