有一個黑客做到這一點。
編寫擴展,以查看控制器:
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(...
喜@yunus IM這樣做... –
嗯我沒有寫很長一段時間Objective-C讓我試試:) –
我想你可以弄清楚如何調用它? –