【发布时间】:2015-11-24 09:56:54
【问题描述】:
当我在viewDidLoad 和viewDidAppear 之前调用performSegueWithIdentifier 时,有时会起作用,有时会不起作用。
AppDelegate
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"applicationDidBecomeActive");
[self abcNotif]; // the method post the notification.
}
VC1:
-(void)awakeFromNib {
NSLog(@"awakeFromNib");
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(theNotif:) name:@"abcNotif" object:nil];
}
-(void)theNotif:(UILocalNotification*)notif {
if([[[NSUserDefaults standardUserDefaults]valueForKey:@"flag"]isEqualToString:@"YES"]) {
[self performSegueWithIdentifier:@"seg1" sender:self];
NSLog(@"theNotif = %@", [[notif userInfo]valueForKey:@"notif1Key"]);
}
}
登录控制台
awakeFromNib
didFinishLaunchingWithOptions
applicationDidBecomeActive
theNotif = notif1Value
viewDidLoad
尽管在viewDidLoad 和viewDidAppear 之前调用了performSegueWithIdentifier,但一切正常。但在某些情况下,这不起作用。为什么会有这种行为。人们也问了这些问题Why doesn't performSegueWithIdentifier work inside viewDidLoad?
【问题讨论】:
标签: ios objective-c uiviewcontroller uistoryboardsegue nsnotificationcenter