views:

672

answers:

2

I have a problemetic UITableViewController fails to redraw an updated cell after a child view is removed.

Here's what's happening. After changing data in a child view, the parent view controller reloads the source data array and runs [tableView reloadData] via a PostNotification. After this triggers, I use popViewControllerAnimated to return to the parent UITableViewController (this pops the child view off the stack, and reveals the controller one level up).

However, my updated data does not appear in the parent view controller! According to the debugger, the cell's label has been updated, but the visible label does not change. However, if I scroll-flick the table, momentarily moving the updated cell out of view, when it reappears the label is updated!

I also try calling [tableView reloadData] via viewWillAppear but the issue still persists.

Here is some additional info that may be helpful. I have a 3 views structured like this:

1/  SettingsViewController : UITableViewController
2/  -- UserView : UITableViewController
3/  ---- UserDetailsView : UIViewController <UIActionSheetDelegate>

I am calling UserDetailsView from inside UserView as follows:

 UserDetailsView *userDetailsView = [[UserDetailsView alloc] init];
 [self.navigationController pushViewController:userDetailsView animated:YES];

If I return to the top-most controller (SettingsViewController) and then load the problematic controller (UserView), everything is drawn correctly. It is only when returning from a child view that this issue occurs.

Thank you in advance for your suggestions.

A: 

Finally worked this one out after about an hour of paired coding.

After a while We noticed that tableView was always null whenever we sent the reloadData message. As you may know in Objective C, null objects accept any message without complaint.

It turns out that "someone" (ahem, sorry it was me) had defined this line in the header file.

 UITableView *tableView;

Now you smart cookies out there will know that because we extend UITaleViewController, we do not need to make a pointer to tableView ourselves. In effect I had replaced the inherited tableView member with a null object.

Mystery solved. Hopefully this helps someone else out there too! :D

crunchyt
A: 

Not an answer; I have the exact same problem! However I'm not using a UITableViewController. I have placed my tables, set the delegate and data source back to the File's Owner, but did declared IBOutlet UITableView *myTableView; in my header. I use the reference pointer back to table. However, I also noticed that myTableView is (null) while running the app. I can't get the [myTableView reloadData]; to work in the viewWillAppear, viewDidLoad, or viewDidAppear for my fourth ViewController.

There are four viewcontrollers in total. The first three each with their own tables, model, detailedViewController, and customCells. The fourth presents a combination of the first three by using their models, customCells and detailedViewControllers to push and pop in order to alter table data. I have a [SAVE] button on the detailedView controller which popsbacktoRootController and saves the changes to the model.

The data models are being updated fine, everything works every where else, except the when the fourth tableView comes back onto the screen the viewWillAppear nor viewDidAppear will execute the [reloadData] on the tableView.

The tableViews reload fine in their own respective viewcontrollers and update the tableViews with their newly populated information fine. I have read crunchyt's comment about the (null) and I too have this, but how else can I point to the tableView without having an IBOutlet.

I'm using a tabBar to switch among views. I have tested the didLoad, willAppear, didDisappear, didAppear with NSLog triggers, and they are all working. But trying to force any of them to [myTableView reloadData]; just does not get triggered. The way that I got the first three views to work was putting an id root variable in the header, then setting the cell.root = tableView; in the cellForRowAtIndexPath: method of each. Then inside the customCell I have a button on the cells that triggers -changeStatus: (a method to switch the image on the cell and trigger the reload of the table so that the table present the new image) I placed [root reloadData]; at the end of the function, and it works great. It references back to the tableView and calls the reloadData method. However, this will not work for my fourth viewController, because the first three's customCells, and I don't have a way to reference back to the fourthVC.

Any Help or Ideas?? I just need a way to force a reload of the table??

Newbyman
Newbyman
Newbyman
If not an answer, add as comment.
Jann