这几天升级了xcode5.1.1,准备写点二级页面动画,结果遇到各种crush...泪奔...
简单说下,有三个view,分别是viewController(自动生成),FirstController,SecondController,架构为:直接将FirstController.view添加到viewController.view上,FirstController.view上有一个按钮action,点击后将跳转到SecondController上。
先用的storyboard,直接将点击事件关联到代码文件中,代码这样写:
//ViewController.m
-(void)ViewDidLoad{
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
FirstController *firstController = [mainSB instantiateViewControllerWithIdentifier:@"FirstController"];
[self.view addSubview:firstController.view];
}
结果FirstController里的点击事件什么事件都不写也会Crush。
其实加一句话就好了
//ViewController.m
-(void)ViewDidLoad{
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
FirstController *firstController = [mainSB instantiateViewControllerWithIdentifier:@"FirstController"];
[self addChildViewController:firstController];
[self.view addSubview:firstController.view];
}
嗯嗯,就是这样!
==========
O ,有句话可以缩写:
FirstController *firstController = (FirstController*)[self.storyboardinstantiateViewControllerWithIdentifier:@"FirstController"];