应用程序收到推送通知后,我想更改主要部分按钮的标题ViewController
.为了实现这个行为,我在我的应用程序委托方法中覆盖了application: didReceiveRemoteNotification:
重新实例化UINavigationController
控制器的方法,我想将其更新为根视图控制器,将按钮的标题设置为我想要的:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
[self.window setRootViewController:navController];
[self.welcomeViewController.buttonToUpdate setTitle: @"Updated Text" forState: UIControlStateNormal];
}
Run Code Online (Sandbox Code Playgroud)
虽然这可能不是最好的解决方案(也许我可以UIButtons
完全忘记并使视图控制器使用UITableView
其行充当按钮?),但它适用于以下场景:
1)应用程序在前台.弹出推送通知提醒,用户触摸OK,视图更新正常.
2)应用程序在后台/关闭.设备处于锁定模式.推送通知到达,用户解锁设备,应用程序加载,查看也更新正常.
例如,当用户使用其他应用程序并且推送通知到达时,问题就出现了,但是用户不是通过推送通知而是通过点击应用程序图标来打开应用程序.在这种情况下,application: didReceiveRemoteNotification:
似乎没有被调用,问题中的视图永远不会更新.
希望我的解释清楚.我愿意接受有关不同方法的建议,或者如何使用我的方法处理最后一个方案.
谢谢!