UITableViewCell not being refreshed upon display?
I have a really weird issue with UITableView/UITableViewCells.
I have a plain styled UITableView that displays a list of objects (for argument, lets say MenuItemsViewController), which has a child object named ItemViewController. MenuItemsViewController just changes the menuItem property on ItemViewController when the 开发者_运维百科user selects an object in MenuItemsViewController.
When the user selects their first item, everything is displayed fine. However, upon subsequent selections of other items, the data in the first section of the ItemViewController doesn't change - i.e. it still displays the properties of the very first item. I've set breakpoints at the end of my tableView:cellForRowAtIndexPath:
and tableView:willDisplayRowAtIndexPath:
methods, and querying cells as they're displayed shows the textLabel/detailTextLabel properties are all correct - i.e. internally they have exactly the state they're supposed to. However, UITableView still isn't displaying the correct information.
Any help is appreciated - this issue is driving me insane. I'm recording and uploading a video to YouTube now to demonstrate, since it's such a bizarre issue that I think people might misunderstand what I'm asking.
edit: and video - http://www.youtube.com/watch?v=AwHTaHCQtX8&feature=youtube_gdata_player
EDIT #2: So, this is insane: after 6 hours straight of debugging and testing, it turns out the animation issue is caused by calling a getter on an NSManagedObject that is faulted...I have no idea why. None. I guess this is sort of a Core Data question now, so I'm adding that as a tag.
You have to tell to table view that its content is changed. Possible solution would be adding [self.tableView reloadData]
to the viewWillAppear:
method of ItemViewController.
But I highly recommend you to override menuItem property and add code to overload only changed cells/sections using reloadRowsAtIndexPaths:withRowAnimation:
/reloadRowsAtIndexPaths:withRowAnimation:
, respectively.
When you select an item in the first table view it should be creating a new child view controller and passing in the NSManagedObject to the child for population. When you pop from the client back to the parent, the child should be getting dealloc`ed. I suspect you are trying to re-use the child view controller (based on your video) otherwise you would not be running into this issue.
So lets start there. Can you confirm that is in fact what you are doing? If not, why not?
精彩评论