objective c - perform segue to initial view from any view with Storyboards -


i developing application using storyboards. application requires user logged in.

the storyboard has login view initial. when login ok, performs segue tabviewcontroller.

on call api, check if server returns 401 (not-authorized). if happens, boolean set false (boolean islogged). appdelegate observes boolean. if value changed false, want return user login screen (remember, initial view on storyboard).

here code:

- (void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context {  if ([keypath isequaltostring:@"islogged"]) {     bool logged = [[change objectforkey:nskeyvaluechangenewkey] boolvalue];     if (logged) {         nslog(@"logged in succesfully!");     } else {         nslog(@"logout performed");          [self.window makekeyandvisible];         [self.window layoutsubviews];      }  } 

this works fine, when try login again loginok segue not performed.

i have tried many other options, this:

uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil];  uiviewcontroller *logincontroller = [storyboard instantiateviewcontrollerwithidentifier:@"login"];  [source presentmodalviewcontroller:logincontroller animated:yes]; 

but problem don't know view controller performed logout. source has current view controller shown in application, isn't it?

finally solved problem changing observer islogged app delegate custom tabviewcontroller. in viewdidload subscribe var.

in method observevalueforkeypath following:

uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil];  loginviewcontroller *logincontroller = [storyboard instantiateviewcontrollerwithidentifier:@"login"];   [self presentmodalviewcontroller:logincontroller animated:yes]; 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -