简体   繁体   English

第二次启动View Controller后,Superview无效

[英]Superview is Nil after Second Launch of View Controller

I've spent hours and I cant figure this out. 我已经花了几个小时,无法解决这个问题。 I have a detail view controller (UITableView) which is launched here: 我有一个详细视图控制器(UITableView),在这里启动:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    EventLocationDetailController *newDetailViewController = [[EventLocationDetailController alloc] initWithNibName:@"EventLocationDetailController" bundle:nil];
    self.eventDetailController = newDetailViewController;
    [self.navigationController pushViewController:self.eventDetailController animated:YES];

    [newDetailViewController release];

}

In the detail view controller there is a button method which calls the below method to display a slide-in-slide-out animation confirming the users choice: 在详细视图控制器中,有一个按钮方法,该方法调用以下方法以显示滑入滑出动画,以确认用户的选择:

-(void)confirmLastActionWithMessage:(NSString *)message {

ConfirmActionViewController  *newConfirmActionViewController = [[ConfirmActionViewController alloc] initWithNibName:@"ConfirmActionViewController" bundle:nil];
self.confirmActionViewController = newConfirmActionViewController; 
[newConfirmActionViewController release];

[[self.view superview] addSubview:self.confirmActionViewController.view];

} }

Protocol method called by the ConfirmActionViewController indicating that the animation is finished. ConfirmActionViewController调用的协议方法,指示动画已完成。

-(void)didFinishConfirmDisplay:(UIView *)viewToRemoveFromSuperview {

     [viewToRemoveFromSuperview removeFromSuperview];
}

This works perfect the first time I press the button. 当我第一次按下按钮时,这种方法非常完美。 If I pop the detail controller and push it back on to the stack and press the button again, nothing happens and the detail controller's superview is nil every time I invoke the method after that. 如果我弹出详细信息控制器,然后将其推回到堆栈上,然后再次按下按钮,则什么也不会发生,并且每次我在之后调用该方法时,详细信息控制器的超级视图都为零。 Superview is not nil in the viewWillAppear method for the detail view, only when It gets to the confirmLastActionWithMessage method. 仅当详细视图的viewWillAppear方法进入confirmLastActionWithMessage方法时,Superview才为零。 No other user interaction happens in between. 之间没有其他用户交互。 How do I get the superview back? 如何获得超级视图? I have a similar code that works without animation. 我有一个类似的代码,无需动画即可工作。

I've also noticed that the detail view controller hasn't called dealloc when popped off the stack. 我还注意到,当从堆栈中弹出时,详细信息视图控制器没有调用dealloc。 Not sure where the problem is. 不知道问题出在哪里。

Thanks. 谢谢。

EDIT 1 编辑1

OK. 好。 I replaced the addSubview line with this one: 我用以下内容替换了addSubview行:

[self.view insertSubview:self.confirmActionViewController.view atIndex:0]; [self.view insertSubview:self.confirmActionViewController.view atIndex:0];

and the animation view appeared underneath one of the table cells. 并且动画视图出现在表格单元格之一的下方。 Could one of the table cells steal the superview? 表格单元之一可以窃取超级视图吗?

Well I don't really understand why you should add the subview to the superview. 好吧,我真的不明白为什么要将子视图添加到超级视图中。 Why not add it just to self.view 为什么不将其仅添加到self.view

I may not be able to explain why there is no superview but try either adding the controller view to self.view or 我可能无法解释为什么没有超级视图,但是尝试将控制器视图添加到self.view或

[[[[UIApplication sharedApplication] delegate] window] addSubview:yourview];

This will render the view on top of everything. 这将使视图呈现于一切之上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM