我正在使用UILocalnotification ...接收通知我在应用处于活动模式时打开viewcontroller ...但是如果同时收到多个通知...我如何打开多个viewcontroller ...上面彼此并顺序解雇它们....我尝试打开viewcontroller但收到此错误
Warning: Attempt to present <NotificationViewController: 0x7fc033b43900> on <UINavigationController: 0x7fc031859600> whose view is not in the window hierarchy!
答案 0 :(得分:1)
有一个黑客可以做到这一点。
为视图控制器写一个扩展名:
extension UIViewController {
var lastPresentedViewController: UIViewController {
guard let presentedViewController = presentedViewController else { return self }
return presentedViewController.lastPresentedViewController()
}
}
或objc:
的UIViewController + LastPresentedViewController.h:
@interface UIViewController (LastPresentedViewController)
-(UIViewController *)lastPresentedViewController;
@end
的UIViewController + LastPresentedViewController.m:
@implementation UIViewController (LastPresentedViewController)
- (UIViewController *)lastPresentedViewController {
if (self.presentedViewController) {
return [self.presentedViewController lastPresentedViewController];
} else {
return self;
}
}
@end
当您需要从navigationController呈现视图控制器时,只需调用此方法:
navigationController.lastPresentedViewController.presentViewController(....
如果您已经在navigationController中,请调用lastPresentedViewController.presentViewController(...