【发布时间】:2012-02-27 10:28:31
【问题描述】:
我的故事板中有一个视图,我为它分配了一个名为“MainView”的标识符。但是,如果我将其视图添加到子视图中,随后的一切都会导致崩溃(例如按下按钮)
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"];
[self.view addSubview:mvc.view];
这是按钮触发的动作:(MainViewController.h)
-(IBAction)showUsername:(id)sender{
[testLabel setText:@"username"];
}
和崩溃日志:
-[MainViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x44e0810
我使用 ARC。
【问题讨论】:
-
instantiateViewControllerWithIentifier:创建一个自动释放的对象。你必须在这里
-retain它,并在不再需要它时释放它。 -
我用的是ARC,所以不支持调用
retain...
标签: iphone objective-c uiviewcontroller storyboard automatic-ref-counting