开发者

Where to add an observer to the NotificationCenter in a UITableViewController

开发者 https://www.devze.com 2022-12-28 13:22 出处:网络
I want to send a notification from a UITableViewController-A to UITableViewController-B. I was adding the observer in the initwithCoder of the UITableViewController that is supposed

I want to send a notification from a UITableViewController-A to UITableViewController-B.

I was adding the observer in the initwithCoder of the UITableViewController that is supposed to catch the notifications.

The classes are correlated as folows

RootViewController

===NavigationController-A

=====UITableV开发者_StackOverflowiewController-A

===NavigationController-B

=====UITableViewController-B

I need to add the observer before the views are actually loaded because notifications may be sent before the view is called.

However I have been told that initializing in the initWithCoder method in a UIViewController is not advisable, and was told to add the observer in the AppDelegate.

Are there any other suggestions for doing this?


I would implement the Notification wiring in 'viewDidLoad' and then force the loading of both view controllers. To force the views to load, get 'UITableViewController-A.view'. It will see the view is not initialized and load the view from the nib, then execute 'viewDidLoad'.

0

精彩评论

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