objective c - How to open an existing viewcontroller in ios -
i need open existing viewcontroller appdelegate while receiving push notification. opening new 1 every time issue is called viewdidload every time , variable reinitialized again , again.
- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo { [[nsuserdefaults standarduserdefaults] setobject:@"yes" forkey:@"got message"]; [[nsuserdefaults standarduserdefaults] setobject:userinfo forkey:@"message"]; [[nsuserdefaults standarduserdefaults]synchronize]; homeviewcontroller* room = [[homeviewcontroller alloc] init]; [self.window.rootviewcontroller presentviewcontroller:room animated:no completion:nil]; }
try so:
- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo { [[nsuserdefaults standarduserdefaults] setobject:@"yes" forkey:@"got message"]; [[nsuserdefaults standarduserdefaults] setobject:userinfo forkey:@"message"]; [[nsuserdefaults standarduserdefaults]synchronize]; [self.window.rootviewcontroller presentviewcontroller:self.room animated:no completion:nil]; } - (uiviewcontroller *)room { if (_room == null) { _room = [[homeviewcontroller alloc] init]; } return _room; }
then can reuse view controller (however, exposure view controller in appdelegate, may taste in clean code).
Comments
Post a Comment