1

我使用UILocalnotification ...在接收通知時打開viewcontroller當應用程序處於活動模式...但如果在同一時間接收到多個通知...怎麼做我打開多個視圖 - 控制......上述相互順序解僱他們....我試圖打開視圖 - 控制,但收到此錯誤iOS:處理與多個相同的viewcontroller多個uilocalnotification

Warning: Attempt to present <NotificationViewController: 0x7fc033b43900> on <UINavigationController: 0x7fc031859600> whose view is not in the window hierarchy! 

回答

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使用的Objective-C,你可以幫我只是叫lastPresentedViewController.presentViewController(...

+0

喜@yunus IM這樣做... –

+0

嗯我沒有寫很長一段時間Objective-C讓我試試:) –

+0

我想你可以弄清楚如何調用它? –

相關問題