2011-11-17 117 views
0

我运行Mac OS X狮子和Xcode-4.2的UIViewController对象的属性不能访问

在我的应用程序中的AppDelegate.m中:didFinishLaunchingWithOptions方法我有以下的提取物。

UIViewController *viewController1 = [[WSWFirstViewController alloc] initWithNibName:@"WSWFirstViewController" bundle:nil]; 
UIViewController *viewController2 = [[WSWSecondViewController alloc] initWithNibName:@"WSWSecondViewController" bundle:nil]; 
self.tabBarController = [[TabBarController alloc] init]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 

self.window.rootViewController = self.tabBarController; 

[self.tabBarController showSplash]; 

[viewController1 displayItems]; 

我试图做的是访问viewController1对象,它是类型WSWFirstViewController的displayItems财产。

在WSWFirstViewController.h我

@property (retain, nonatomic) NSMutableArray *displayItems; 

在WSWFirstViewController.m我已经@synthesized displayItems。

我似乎无法弄清楚,为什么我得到一个:

住宅“displayItems”上输入“*的UIViewController”的对象没有找到。

直到我注意到我的对象(viewController1)不是UIViewController *类型,而是WSWFirstViewController *。但仍然没有帮助我更进一步。

任何意见是赞赏!

回答

1

你应该通过他们的正确类型是指你的控制器:

WSWFirstViewController *viewController1 = [[WSWFirstViewController alloc] initWithNibName:@"WSWFirstViewController" bundle:nil]; 
WSWSecondViewController *viewController2 = [[WSWSecondViewController alloc] initWithNibName:@"WSWSecondViewController" bundle:nil]; 

.... 

[viewController1 displayItems]; // this will now work if you are in the same context 
+0

这就是您重复使用生成的代码所得到的结果。感谢您指出了这一点! –

+0

很高兴有帮助! – sergio

0

你在界面的NSMutableArray displayItems声明?