views:

118

answers:

1

I have this working but I don't think it is working correctly so I just wanted to get your feedback. I am trying to display a screen that has two buttons - one that takes you to a login screen and the the allows you to register.

II am testing in the appDelegate if they are logged in and if they aren't I am showing the signLogIN view.

signLogIN = [[LoginOrSignUPViewController alloc] init];

signLogIN.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
signLogIN.tabBarController = mainAPPTabBarController;
signLogIN.mainWindow = window;
[window addSubview:[signLogIN view]];
//[signLogIN release];

(I release in the appDelegate dealloc - if I release here it blows up when they select to either login or register).

I did try doing:-

[mainAPPTabBarController presentModalViewController:signLogIN animated:NO];

But it made no difference.

Curiously I can see that the dealloc in LoginOrSignUPViewController is called straight away - why is that? I can't tell where it is being called from.

From LoginOrSignUPViewController I am then displaying the login screen by doing:-

[self retainCount] = 1

LoginViewController *logINVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];

logINVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
logINVC.delegate = self;
logINVC.tabBarController = self.tabBarController;
[self presentModalViewController:logINVC animated:YES];
[logINVC release];

now [self retainCount] = 3 = why did it go to three????

As you can see there is a delegate that calls back to the signLogIn view to close the view as follows:-

[self retainCount] = 3
[mainWindow bringSubviewToFront:tabBarController.view];
tabBarController.selectedIndex = 0;

[self.view removeFromSuperview];
[self dismissModalViewControllerAnimated:NO];
[self release];

[self retainCount] = 3  -- still 3 it never goes away

So here is my main problem LoginOrSignUPViewController never goes away it just sits behind my main view. The only line that makes any difference is the [mainWindow bringSubViewToFront. Does anyone have any ideas as to how to make the LoginOrSignUPViewController disappear?

Thanks very much Cheryl

A: 

Have you tried this in your view controller's viewDidLoad:

LoginOrSignUPViewController *signLogIN = [[LoginOrSignUPViewController alloc] init];
[self presentModalViewController:signLogIN animated:NO];
[signLogIn release];
christo16
I am not calling this from a view controller but from my appDelegate. Perhaps I should call it from the view controller but I worry that the first view controller into my app may change and I will be caught out. I thought it was safest and cleanest to load it from the appDelegate.
Cheryl
Since this VC is only called when registering/login expired, best practice would probably be to show it modally from something like a "Main View Controller", rather than setting it to your window's view. You can do this in a way so that the user won't see the view controller underneath, until they've successfully dismissed (by logging in or registering) the modal.
christo16