在一个tableview的选中事件中,我弹出了一个subView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
myViewController *ViewController =[[myViewController alloc]initWithNibName:@"myViewController" bundle:nil];
//[self.navigationController pushViewController:ViewController animated:YES];
[self.view addSubview:ViewController.view];
然后在subView中,我执行
- (IBAction)remove:(id)sender
{
[self.view removeFromSuperview];
}
结果是整个app都关闭了,而不是关闭subView,回到tableView所在的view
------解决方案--------------------
你尝试一下
[ViewController.view removeFromSuperview];
------解决方案--------------------
果然是崩溃了。
崩溃的原因是你调用了release没错。
首先,你的理解是错误的。
是你alloc的,你就要负责到底,你要调用release,不会自行释放。
不可以去掉super dalloc(去掉了有一些东西就没释放)
viewcontroller没释放,你点一下,内存泄露一次。
和tableview无关。
addsubview和push不一样,push可以release,因为它内部retain了,addsubview就不可以,因为controller都没了,view也不能用了。
如果不想push,可以使用做一个成员变量来管理,让他来retain,你就可以调用release了。