简体   繁体   English

从超级视图中删除modalViewController后,UIView消失

[英]UIView disappears after modalViewController is removed from superview

In my app I have a tabBarController and in it a navigationController. 在我的应用程序中,我有一个tabBarController和一个navigationController。 One of my view controllers is a TableViewController and under the navigationBar i added a uiView as a subview to the view like this: 我的视图控制器之一是TableViewController,在navigationBar下,我向视图添加了uiView作为子视图,如下所示:

rectangleInfo = [[UIView alloc] initWithFrame:CGRectMake(0,0,[[UIScreen mainScreen] applicationFrame].size.width,26)]; rectangleInfo.autoresizingMask = (UIViewAutoresizingFlexibleWidth); rectangleInfo.backgroundColor = [UIColor darkGrayColor]; [self.view addSubview: rectangleInfo];

when I click on a cell in the tableView I push an UIViewController like this: 当我单击tableView中的单元格时,我按下了UIViewController:

[feedViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

[[self navigationController] presentModalViewController:feedViewController animated:YES]; [[self navigationController] presentModalViewController:feedViewController动画:是];

After i pop the modal view for a couple of times with it from the tableViewNavigationController disappears the rectangleInfo UIView. 在我从tableViewNavigationController弹出模态视图几次后,rectangleInfo UIView消失了。

I pop my modalview like this: 我像这样弹出我的模态视图:

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self dismissModalViewControllerAnimated:YES];

any idea why that subview (rectangleInfo) of the tableViewController dissapears after i remove the modal view from the superview? 任何想法为什么我从超级视图中删除模式视图后,tableViewController的子视图(rectangleInfo)消失了?

thank you in advance. 先感谢您。

I'm curious as to what you are trying to do with your rectangleInfo view? 我很好奇您要对您的rectangleInfo视图做什么? By the size of it, it looks like you are trying to mimic the status bar. 根据它的大小,您似乎在模仿状态栏。 Why? 为什么? You can just hide the status bar if you want. 您可以根据需要隐藏状态栏。

Another thing you can try is to create the UIView visually in Interface Builder. 您可以尝试的另一件事是在Interface Builder中直观地创建UIView。 Don't actually add it to your main view, but create it as a separate UIView in the XIB with the appropriate size, etc. Then create an outlet for it in Xcode and connect it. 实际上,不要将其添加到主视图中,而是在XIB中将其创建为具有适当大小的单独UIView,以此类推。然后在Xcode中为其创建出口并连接它。 Next, add it as a subview in code when your view controller loads. 接下来,在加载视图控制器时,将其添加为代码中的子视图。 See if that makes a difference. 看看是否有区别。 This is especially strange since you say it only disappears after popping it several times. 这尤其奇怪,因为您说它仅在弹出几次后才会消失。 Do you get the same problem if you push and pop the non-modal way, eg: 如果以非模式方式推送和弹出,是否会遇到相同的问题,例如:

[[self navigationController] pushViewController:feedViewController animated:YES];
[[self navigationController] popViewControllerAnimated:YES];

我通过正确实现用于创建和释放子视图的viewDidLoad和viewDidUnload方法解决了该问题。

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

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