ViewController 被释放,导致崩溃
我的故事板中有一个视图,我为其分配了一个名为“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。
I have a view in my storyboard which I assigned an identifier called "MainView". However if I add its view to the subview, everything that follows produces a crash (e.g. pressing a button)
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"];
[self.view addSubview:mvc.view];
This is the action triggered by the button : (MainViewController.h)
-(IBAction)showUsername:(id)sender{
[testLabel setText:@"username"];
}
and the crash log :
-[MainViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x44e0810
I use ARC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
处理这个问题的最佳方法是使用属性。操作方法如下:
在 .h 文件中:
在 .m 文件中:
Best way to deal with this is using a property. Here's how:
In your .h file:
In your .m file: