开发者

How do I get a reference to a rootViewController to a sub-view?

开发者 https://www.devze.com 2022-12-27 09:37 出处:网络
An answer posted for one of my previous questions brings up anoth开发者_JAVA技巧er question; I am calling a new viewcontroller, \"RuleBuilder,\" from my rootViewController. TherootViewController holds

An answer posted for one of my previous questions brings up anoth开发者_JAVA技巧er question; I am calling a new view controller, "RuleBuilder," from my rootViewController. The rootViewController holds a reference to a contacts array. How do I get a reference to that array into the RuleBuilder? I tried adding

UITableViewController *rootViewController;
...
@property (nonatomic, retain) UITableViewController *rootViewController;

to RuleBuilder.h, and then

@synthesize rootViewController;

in RuleBuilder.m. When I instantiate and push the RuleBuilder from within rootViewController, I do this:

ruleBuilder.rootViewController = self;

But when I try this

[rootViewController.contacts addObject:newContact];

from within RuleBuilder, I get a compiler error to the effect of "request for 'contacts' in something not a struct" (or very similar; I haven't implemented this exact snippet of code, but I tried an identical approach not an hour ago for a couple of different references that I never was able to get working).

Thanks, again, for your help.


You've declared the rootViewController property as a UITableViewController (which does not have a "contacts" property).

Most likely, your root view controller is a subclass of UITableViewController. If you called that subclass RootViewController, then the rootViewController property in RuleBuilder should be declared as

RootViewController *rootViewController
0

精彩评论

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

关注公众号