开发者

ViewController Hierarchy getting 'lost'

开发者 https://www.devze.com 2023-04-04 22:34 出处:网络
I\'ve got a view hierarchy which is setup (programmatically) as follows: Window.root = TabBarController-->UINavigationControllers-->UIViewControllers

I've got a view hierarchy which is setup (programmatically) as follows:

Window.root = TabBarController-->UINavigationControllers-->UIViewControllers

I presume that's rather standard. Here's开发者_高级运维 my problem:

I'm on Tab A. I want to navigate to Tab B, and call a method on the visibleViewController on Tab B.

// View Changes OK
[AppDelegate.tabBarController setSelectedIndex:tabB];

// nav  = 0x387ABF i.e. Valid Address
UINavigationController *nav = (UINavigationController*)[AppDelegate.tabBarController selectedViewController];

// The problem:
nav.viewControllers; // this is nil
nav.topViewController; // as is this
nav.visibleViewContorller; // this too.

Even if I put the calls to nav.viewControllers in a separate method which is called from the Main Thread, I still get 0x0/nil.

What am I doing wrong?

A follow-up question is: How can I pass information from one ViewController to another when changing tabs? (If I can't call methods on VC's from tabA to tabB)

I have a feeling it is related to my question here.


You should store the information in a common place, either a singleton or as you are a beginner just make a class and pass it down.

sharedDataObject = [[MySharedDataObject alloc] init];

firstViewController.myDataObject = sharedDataObject;
secondViewController.myDataObject = sharedDataObject;
0

精彩评论

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

关注公众号