[英]removeFromSuperView don't work on iOS 8
I'm adding a view over my main view like this: 我在主视图上添加一个视图,如下所示:
self.voteResult = [[voteResultViewController alloc]initWithNibName:@"voteResultViewController" bundle:nil];
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview:[self.viewControllerForPresentation view]];
[self.viewControllerForPresentation presentViewController:self.voteResult animated:YES completion:Nil];
And then removing it with this: 然后使用以下命令将其删除:
[self.viewControllerForPresentation.view removeFromSuperview];
Works in iOS 7, but not longer in iOS 8, do I need to do anything different? 在iOS 7中有效,但在iOS 8中不再有效,我需要做其他不同的事情吗?
It looks like you're doing too much work here. 您似乎在这里做了太多工作。 You're adding
self.viewControllerForPresentation.view
to the view yourself using -addSubview:
, but you're also presenting the view controller using -presentViewController:animated:completion:
. 您要添加
self.viewControllerForPresentation.view
使用到视图自己-addSubview:
但你也呈现使用视图控制器-presentViewController:animated:completion:
。 That method presents the view controller in question, which should then take care of adding the view to the view hierarchy. 该方法提供了相关的视图控制器,然后应负责将视图添加到视图层次结构中。 To remove the view, you'd use
-dismissViewControllerAniamted:completion:
and that in turn should remove the view appropriately. 要删除视图,您可以使用
-dismissViewControllerAniamted:completion:
这又应该适当地删除视图。
In short, either add and remove the view yourself using -addSubview:
and -removeFromSuperview
, or present the view controller that owns the view using -presentViewController:animated:completion:
and dismiss it using -dismissViewControllerAniamted:completion:
. 简而言之,您可以使用
-addSubview:
和-removeFromSuperview
自己添加和删除视图, 或者使用-presentViewController:animated:completion:
呈现拥有视图的视图控制器,然后使用-dismissViewControllerAniamted:completion:
将其关闭。 Don't to do both. 不要两者都做。
尝试这个。
[self dismissViewControllerAnimated:voteResult completion:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.