Sha*_*ali 5 iphone crash exc-bad-access subview superview
我确定这是一个愚蠢的错误,但我正在尝试过去一小时从我的超级视图中删除子视图而没有任何成功.
在我的第一个观点上,我有
UIViewController *helpView = [[[UIViewController alloc] initWithNibName:@"HelpView" bundle:nil] autorelease];
[self.view addSubview:helpView.view];
Run Code Online (Sandbox Code Playgroud)
然后在帮助视图中我有一个连接到名为"closeHelp"的IBAction的按钮,它只执行以下操作:
- (IBAction) closeHelp{
[self.view removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
但是这会导致我的应用程序因EXC_BAS_ACCESS崩溃而出于某种奇怪的原因,即使是在HelpView中也是如此,这意味着self.view应该指向正确的子视图.
非常感谢你的帮助
谢谢.
夏嘉曦.
小智 5
正如安德烈亚斯回答的那样,您正试图从超级/父级视图中删除self.view.您基本上需要从其父视图中删除helpView.
所以它应该是
- (IBAction) closeHelp{
[helpView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
但是我们不知道上面方法中的"helpView"是什么.因为我们没有任何处理它.
所以我们的代码最终应该是这样的.
#define HELP_VIEW_TAG 101 // Give tag of your choice
HelpView *helpView = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];
helpView.view.tag = HELP_VIEW_TAG;
[self.view addSubview:helpView.view];
[helpView release];
- (IBAction) closeHelp{
UIView *helpView = [self.view viewWithTag:HELP_VIEW_TAG];
[helpView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5880 次 |
| 最近记录: |