开发者

iPhone: Technique UITableController tell previous UITableController it needs to update

I have a UINavigationController with two UITableViewControllers (A and B).

A is displayed first and when the user taps a row on the display, A loads UITableViewController B and pushes it onto the stack.

The user can then update some data in B's UITableView which may result in the tapped row on A's UITableView needing to be updated.

The problem I'm trying to nut out is the best way for UITableViewController B to let UITableViewController A know that it needs to update the row.

I've thought of a number of different ways of doing this including:

  • Having A store the IndexPath and a reference to B so that when ViewWillAppear is called, it can check properties of B and then reload the cell at the IndexPath.

  • Have A monitor the core data NSMangedObjectContext through the notification system. Both controllers feed their data from core data. A would still need to store the IndexPath.

  • Having B somehow (through the UINavigationController?) look up the previous controller (A) and tell it that it needs t开发者_StackOverflow社区o update the row.

None of these seem that eligant.

Is there a better way to do this?


The second one is the most elegant to me (and you could tweak it with KVO instead of notifications).

And it is since it does not load B with more responsibilities that he needs (B cannot even know about A) whereas the third option makes B notify A. Plus it will be more independent from changes than the first one (because you are obliged to check the situation before A is loaded, and you use ViewWillApperar:, but this situation can change in the future)


why not use NSNotificationCenter?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜