Add CollectionViewController as ChildViewController to UIView
I am trying to create a view that contains three subqueries that have different view controllers ( UICollectionViewController
, pageviewcontroller
and uiviewcontroller
). I can add uiviewcontroller
, but the other two controllers are not allowed. I am getting this error .....
Incompatible pointer types sending 'UICollectionView * __ weak' to parameter of type 'UIViewController *'
Is there any way to add this controller to my submission?
source to share
I don't know why you want to add ViewControllers inside the view, I never need it. I tried to do this, if it can help you, this is my code:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (nonatomic, retain) UICollectionViewController *collectionViewController;
@property (nonatomic, retain) UIPageViewController *pageViewController;
@property (nonatomic, retain) UIViewController *simpleViewController;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize collectionViewController;
@synthesize pageViewController;
@synthesize simpleViewController;
- (void)viewDidLoad
{
[super viewDidLoad];
UICollectionViewLayout *layout = [[UICollectionViewLayout alloc] init];
collectionViewController = [[UICollectionViewController alloc] initWithCollectionViewLayout:layout];
pageViewController = [[UIPageViewController alloc] init];
simpleViewController = [[UIViewController alloc] init];
// Do your stuff with this controllers
[self.view addSubview:collectionViewController.view];
[self.view addSubview:pageViewController.view];
[self.view addSubview:simpleViewController.view];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
source to share
You are not adding view controllers to views. You add views to views (as subviews) and, more rarely, to controllers (as child controllers).
Think of them as two parallel hierarchies: Given ControllerA
which controls the view ViewA
you want to make the ControllerB
child controller ControllerA
look like ViewB
is a sub ViewA
.
Watch the WWDC 2011 video : "Implementing the UIViewController Containment"
source to share