【问题标题】:iOS : Handle multiple uilocalnotification with multiple same viewcontrolleriOS:使用多个相同的视图控制器处理多个 uilocalnotification
【发布时间】:2016-03-03 11:32:55
【问题描述】:

我正在使用 UILocalnotification...在收到通知时,我在应用程序处于活动模式时打开 viewcontroller...但是如果同时收到多个通知...我如何打开多个 viewcontroller...以上彼此并按顺序关闭它们....我尝试打开视图控制器但收到此错误

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

【问题讨论】:

    标签: ios objective-c iphone uiviewcontroller uilocalnotification


    【解决方案1】:

    有一个技巧可以做到这一点。

    为视图控制器编写扩展:

    extension UIViewController {
        var lastPresentedViewController: UIViewController {
            guard let presentedViewController = presentedViewController else { return self }
            return presentedViewController.lastPresentedViewController()
        }
    }
    

    或对象:

    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(...

    【讨论】:

    • hmm 好久没写objective-c了让我试试:)
    • 我猜你知道怎么称呼它了?
    • 它工作得很好,谢谢...还有一个查询...link
    • 知道当我点击一个通知时如何确认其他 uilocalnotification 吗??
    • 你可以保存旧的或者那些
    猜你喜欢
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多