[英]Cannot pass data between app delegate and storyboard
收到本地通知时,我需要将一个变量设置为NO。 在App Delegate中,我运行:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
if ([[notification alertBody] isEqualToString:@"Time To Wake Up"]) {
NLAlarmViewController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"AlarmVC"];
[vc setStarted:NO];
}
}
在视图控制器类中:
- (IBAction)twoTapsDetected:(UITapGestureRecognizer *)sender {
NSLog(@"Two taps detected");
if (started != YES ) {
NSLog(@"Not Started");
}
else if (started != NO) {
NSLog(@"Started");
}
}
在日志中,我已经开始。 但是在App Delegate中,我将其设置为NO。 当我在Xcode中创建断点时,开始= YES,但应为NO。 也许我做错了什么?
在出现通知时,在appdelegate中执行带有标识符的segue。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
if ([[notification alertBody] isEqualToString:@"Time To Wake Up"]) {
[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:self];
}
}
然后使用故事板委托方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// // Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"YourSegueIdentifier"]) {
// Get reference to the destination view controller
NLAlarmViewController *vc = (NLAlarmViewController *)[segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setStarted:NO];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.