我不知道你爲什麼要在視圖中添加ViewControllers,我從不需要它。 我想這樣做,如果能夠幫助你,這是我跑步代碼:
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
感謝您的時間。其實我也在做同樣的事情,但錯誤在於正在嘗試添加視圖控制器而不是其視圖。愚蠢的錯誤.......再次感謝 – bhawesh 2013-02-16 12:05:57