繁体   English   中英

从appDelegate搜索到视图控制器

[英]Segue to a view controller from appDelegate

我已经设置了一个应用程序来接收推送通知。 当用户收到通知时,我的appDelegate中会有一个回调。 如果该应用程序处于非活动状态,并且用户单击设备面板上的通知,那么我需要能够从此处进行筛选。

该应用程序的流程是一个登录视图控制器(如果loginBool为true,则将被跳过),从而导致一个选项卡控制器。 在选项卡控制器上,我可以在3个地方选择ID为“ FeedDetailedController”的同一个viewController。

它是FeedDetailedController,我需要查询并传递在通知中收到的变量。 可以从3个不同的位置访问此控制器,其中2个是带有表视图的选项卡,当您单击一行时,它将传入变量并执行segue。 我需要模仿我的应用程序委托,即从通知中传入数据,就像我对行所做的那样。

到目前为止的尝试:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        println("received a notification")
        PFPush.handlePush(userInfo)
        if application.applicationState == UIApplicationState.Inactive {
            println("in the notification if with \(userInfo)")

            if let info = userInfo["custom"] as? Dictionary<String, AnyObject> { 
                if  let reportId = info["reportId"] as? String {
                    println("\nFrom APS-dictionary with key \"type\":  \(reportId)")
                    //pass in reportId to the viewcontroller somehow

                    let storyboard = UIStoryboard(name: "Main", bundle: nil)
                    let vc = storyboard.instantiateViewControllerWithIdentifier("NewFeedDetailedController") as! UIViewController

                    let navigationController = UINavigationController(rootViewController: vc)
                    self.window?.rootViewController?.presentViewController(navigationController, animated: true, completion: nil)
                }

            }
            PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
        }
        else{
            println("in the notification else")
            //this is when the app is active, do I need to detect which view   controller I am currently on before I can seg???
        }
    }

当前代码给出以下消息:

Warning: Attempt to present <UINavigationController: 0x12ed763d0> on <UINavigationController: 0x12ed11ce0> whose view is not in the window hierarchy!

这是有道理的,但我不知道如何从appDelegate代码获得正确的层次结构

是否可以在您应用的初始视图控制器中检查该通知? 喜欢将通知作为布尔值传递吗? 您可能看起来像viewWillAppear:并进行检查-是否在该位置控制该视图的序幕,而不是尝试在appDelegate本身中进行?

这样,它似乎可以直接进入新视图,但是真的要通过已将层次结构加载到其中的视图控制器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM