1

I have in my objective-c application a loginViewController from where I display the homeViewController after the user logged in successfully. This is how I display the home:

-(void) displayHome {
UIViewController * home = [self.mainStoryboard instantiateViewControllerWithIdentifier:@"homeViewController"];
    _window.rootViewController = publicHome;
    [_window makeKeyAndVisible];
}

The displayHome function is in the AppDelegate. After that, in the homeViewController i present some view controllers using

[self presentViewController:controller animated:false completion:nil];

Sometimes I have to redirect the user to the loginViewController so I call this VC the same as I do for the home (by setting the rootViewController) in order to remove all the other views. But when I use the 3d debugger I see that the presented views are there. Why when I set the rootViewController with the loginViewController, the presented views are not removed even if there are attached to the homeViewController that is as the rootViewController?

Edit

An example:

Suppose that from the homeViewController(that is the rootViewController) I go to the viewController1 (viewController1 is presented). Now when I press a button in the viewController1 I have to return to the loginViewController. In the button action, this is what I do:

I call

[self dismissViewControllerAnimated:false completion:nil];

and [appDelegate displayLogin];

//AppDelegate
-(void) displayLogin {
UIViewController * login = [self.mainStoryboard instantiateViewControllerWithIdentifier:@"homeViewController"];
    _window.rootViewController = publicHome;
    [_window makeKeyAndVisible];
}

When I debug, I find that the viewController1 is still here. It under the login. Why is the viewController1 here even if I set the rootViewController?

Ne AS
  • 1,490
  • 3
  • 26
  • 58
  • your question is not clear. Presented view controllers are always stay on top on root view controller until u dismiss the presented controller. – Teja Nandamuri Aug 17 '17 at 15:33
  • @TejaNandamuri check my edit please – Ne AS Aug 17 '17 at 15:45
  • try calling [appDelegate displayLogin] in the completion block of dismissViewControllerAnimated. – Teja Nandamuri Aug 17 '17 at 15:47
  • @TejaNandamuri I tried it but the viewController1 is still here – Ne AS Aug 17 '17 at 15:53
  • Two thing 1. Just check if it is dismissing at first place or not don't call displayLogin 2. Try adding delay in displayLogin by using dispatch inside dismiss completion block. – iphonic Aug 17 '17 at 20:32
  • I had faced same issue. You can take help from ans provided to my question I asked previously [here](https://stackoverflow.com/questions/33564261/logout-from-ios-app). – luckyShubhra Aug 23 '17 at 12:16

2 Answers2

0

Maybe you should first check whether the method -dealloc has been executed in you UIViewControllers. Try add this code in viewController1:

- (void)dealloc {
    NSLog(@"ViewController %@ dealloc", NSStringFromClass([self class]));
}

If this method hasn't been invoked, then check whether there is still any strong reference pointing to viewController1 after you called [self dismissViewControllerAnimated:false completion:nil];

liftlift
  • 59
  • 4
-1

This usually happens due to the retaincount, check your implementation and make sure there is no completion block or something which is not letting dealloc get called. Once your dealloc gets called all views will get removed

Muddsar
  • 78
  • 9