ios - Modal View change my Tab when it close -


i have tabbarviewcontroller 2 tabs: tab(a) , tab(b). both tabs has uitableview inside , when click in cell, modal view appears. if click on tab(a) default tab, works fine problem when go tab(b) , after opening modal view, when close modal view tab bar automatically goes default tab tab(a). tried :

[self dismissviewcontrolleranimated:yes completion:nil]; 

and :

[self.presentingviewcontroller dismissviewcontrolleranimated:yes                                                       completion:nil]; 

for going back. have same result.

you can save last view controller selected in tab bar such:

    -(void)tabbarcontroller:(uitabbarcontroller *)tabbarcontroller didselectviewcontroller:(uiviewcontroller *)viewcontroller     {          _previousviewcontrollerindex = // index of tab here     } 

after dismissing model view, viewdidappear called on uitabbarcontroller, , can programatically select previous selected controller:

- (void)viewdidappear:(bool)animated {   [super viewdidappear:animated];   [self.tabbarcontroller setselectedindex:_previousviewcontrollerindex]; } 

Popular posts from this blog