2012-06-29 73 views
0

我怎麼能這四個視圖控制器添加到陣列添加視圖控制器陣列

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];  
ContainerViewController *container= [[[ContainerViewController alloc]init]autorelease]; 
self.window.rootViewController = container; 
NSMutableArray *controllers = [NSMutableArray array]; 
for (int i=0; i<23; i++) 
{ 
    First *first = [[First alloc] init]; 
    Second *second = [[Second alloc] init]; 
    Third *third = [[Third alloc] init]; 
    Fourth *fourth = [[Fourth alloc] init]; 

    [controllers addObject:first]; 
    [controllers addObject:second]; 
    [controllers addObject:third]; 
    [controllers addObject:fourth]; 
    } 

[container setSubViewControllers:controllers]; 
[window makeKeyAndVisible]; 
return YES; 

得到黃色預警實例方法setSubViewController沒有發現返回類型默認爲ID

感謝您的幫助。

回答

1

這集

- (void)setSubViewControllers:(NSArray *)subViewControllers; 
ContainerViewController的.H

這將幫助你擺脫的警告,但我不知道你在做什麼邏輯,也是我會建議你釋放你的子視圖控制器在循環再次分配它們之前...

2

要將視圖控制器添加到數組中,不需要有for循環。在container

​​

對於視圖控制器::取出環,並添加setSubViewControllers不是有效的方法。但是,您可以使用addChildViewController添加子視圖控制器。你可以遍歷你的數組,並調用[container addChildViewController:x#ViewController]; 喜歡的東西:

for (id thisViewController in controllers) { 
thisViewController = (UIViewController *)thisViewController; 
[container addChildViewController:thisViewController]; 
} 

注:我沒有測試此代碼。如果您有任何問題,請告訴我。

相關問題