我添加視圖在我的主視圖像這樣的工作:removeFromSuperView不會在iOS 8
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];
然後用此將其取出:
[self.viewControllerForPresentation.view removeFromSuperview];
作品中的iOS 7,但在iOS 8中不再更長,我需要做不同的事情嗎?
你爲什麼要自己添加視圖,還要使用'-presentViewController:animated:completion:'?該方法呈現視圖控制器,這應該使視圖適當地顯示。然後你應該使用'-dismissViewControllerAnimated:completion:'來關閉控制器,這也將刪除視圖。 – Caleb 2014-11-03 14:57:32