Reputation: 767
How can i add these four view controllers to array
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;
getting yellow warning that instance method setSubViewController not found return type defaults to id
Thanks for help.
Upvotes: 0
Views: 614
Reputation: 12405
set this
- (void)setSubViewControllers:(NSArray *)subViewControllers;
in the .h of ContainerViewController
this will help you get rid of the warning but I am not sure what you are doing logically and also I would advice you to release your sub view controllers in the loop before allocating them again...
Upvotes: 1
Reputation: 1430
To add the view controllers to the array, there's no need to have a for loop. Remove the loop, and add:
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];
For the view controllers in container
: setSubViewControllers
is not a valid method. However, you can add a child view controller with addChildViewController
. You could loop through your array, and call [container addChildViewController:x#ViewController];
Something like:
for (id thisViewController in controllers) {
thisViewController = (UIViewController *)thisViewController;
[container addChildViewController:thisViewController];
}
Note: I haven't tested this code. Let me know if you have any problems.
Upvotes: 2