我正在尝试创建一系列视图,然后我可以在我的申请人中滑动。
我试图在我的视图中设置我的数组,然后加载然后将数组中的第一个视图加载到视图中。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Prototype";
//Initalizse the swipe gestuer listener
[self setupLeftSwipeGestureRecognizer];
[self setupRightSwipeGestureRecognizer];
//alloc and init viewcontroller nibs
self.detailViewA = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
self.detailViewB = [[DetailViewControllerB alloc]initWithNibName:@"DetailViewControllerB" bundle:[NSBundle mainBundle]];
self.detailViewC = [[DetailViewControllerC alloc]initWithNibName:@"DetailViewControllerC" bundle:[NSBundle mainBundle]];
// Create Array
viewArray = [NSArray arrayWithObjects:detailViewA_, detailViewB_, detailViewC_, nil];
// set detail View as first view
[self.view addSubview:[viewArray objectAtIndex:0]];
}
之后它崩溃了。并产生这条消息。
2012-05-31 10:06:33.769 SMPrototypeB[2394:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController superview]: unrecognized selector sent to instance 0x131b00'
答案 0 :(得分:3)
您正在添加视图控制器作为子视图,但您需要做的是添加该viewController的视图。
UIViewController *tempVC = (UIViewController*)[viewArray objectAtIndex:0];
[self.view addSubView:tempVC.view];