就像现有的聊天应用程序(fb chat,imessages)一样,我希望能够在响应通知横幅时将用户带到消息线程屏幕。
VC层次结构:TabBarController - > NavController - > MessageThreadsTVC - > MessagesVC
MessageThreadsTVC本质上是一个联系人列表,当我点击一个联系人时,它会执行一个segue,将所选行的标识符传递给目标VC,以便它知道从服务器提取哪些数据。目前手机上没有数据保留,并且全部来自相关viewDidLoad中的Parse。
到目前为止,我已经能够使用以下方法将应用程序打开到所需的选项卡:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if(application.applicationState == UIApplicationState.Inactive) {
println("Inactive");
//Show the view with the content of the push
// User opened the push notification
var tabbc:UITabBarController = self.window?.rootViewController as UITabBarController
tabbc.selectedIndex = 2
但是,如何浏览2个更多级别的viewController并在MessagesVC中实例化相关变量?我在哪里有时间查询数据库,以便从我在远程通知中传递的objectID字符串中解析匹配的PFUser对象?
答案 0 :(得分:1)
var tabbc:UITabBarController = self.window?.rootViewController as UITabBarController
tabbc.selectedIndex = 2
var navVC = tabbc.selectedViewController as UINavigationController
if (navVC.topViewController.isKindOfClass(MessagesTableViewController)){
navVC.popToRootViewControllerAnimated(false)
}
var topViewController = navVC.topViewController as MessageThreadsTableViewController
topViewController.targetUser = (objects[0] as PFUser)
topViewController.performSegueWithIdentifier("selectThread", sender: topViewController)