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?
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:
. 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.
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:
. Don't to do both.
尝试这个。
[self dismissViewControllerAnimated:voteResult completion:nil];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.