Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a CollectionViewController as ChildViewController to a UIView

I am trying to create a view which contains three subview having different view controller (UICollectionViewController,pageviewcontroller and uiviewcontroller). i am able to add a uiviewcontroller but other two controller is not allowed. I am getting this error.....

Incompatible pointer types sending 'UICollectionView *__weak' to parameter of type 'UIViewController *'

Is their any way to add these controller to my subview?

like image 354
bhawesh Avatar asked Jan 20 '26 20:01

bhawesh


1 Answers

I don't know why you want to add ViewControllers inside a view, i never need it. I tried to do that, if can help you this is my running 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
like image 164
Alessandro Avatar answered Jan 22 '26 10:01

Alessandro