I have an app that has a tabview controller. There are 4+ tabs with each view coming from its own NIB. I am using the NotificationCenter to send messages between the different view controllers.[BTW NotificationCenter is GREAT way to do IPC (interprocess communication).It saves you from having all objects so interconnected.] The problem is that the code to connect to Notification Center needed to be executed pretty earl so I put the calls in the viewDidLoad methods. Early events were missed! It turns out that the OS does lazy loading (for good reasons). That is, objects are not loaded from the NIB files until first accessed. Views not loaded, viewDidLoad methods are not called. This caused several subviews to miss events until the tab was selected! Since the other controllers were not loaded, they missed the events. The problem was now how to get the correct instance of the view loaded and initialized!
The fix was very simple.
You just need to access the views in question to get them loaded.
Here is the code:
UITabBar *tabBar; // the TabBar
// All controllers accessed by the tabs.
NSArray *viewControllers = tabBar.viewControllers;
for (UIViewController *controller in viewControllers)
{
controller.view; // access the view to get it loaded.
}
Thats It!
Just insert this code in your main view controller viewDidLoad method. Word of caution. This might use a lot of memory at startup.
Hope this Helps!
Tìoraidh!
0 comments:
Post a Comment