2012-06-29 72 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]; 
} 

注:我没有测试此代码。如果您有任何问题,请告诉我。

相关问题