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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -