iPhone login screen problem

2019-04-02 08:43发布

问题:

I have a large application. It has a lot of tables and navigation between them. I started a project as a 'NavigationBasedProject' (xcode template). But now I need to add login at the start of the application. So here what I did so far: In 'didFinishLaunchingWithOptions' I added:

loginViewController = [[LoginViewController alloc]init];
        [loginViewController.view setFrame:CGRectMake(0, 0, 320, 480)];
        [self.window.rootViewController presentModalViewController:loginViewController animated:NO];

When user data are valid I dismiss login screen like this:

[self.loginViewController dismissModalViewControllerAnimated:YES];

User can also logout from application. And then I present login screen again like this:

[self.window.rootViewController presentModalViewController:loginViewController animated:NO];

And this works. But text fields on login screen are still filled with data that user enter to login. And I am afraid that I have some memory issue here. How to remove login screen completely from memory when user logs in. I don't use GUI designer I connect everything from code. Also I wonder is it good idea to make login screen and modal view?

回答1:

you should use.... (I don't know why you are declaring it loginViewController at class level)

LoginViewController *loginViewController = [[LoginViewController alloc]init];
            [loginViewController.view setFrame:CGRectMake(0, 0, 320, 480)];
            [self.window.rootViewController presentModalViewController:loginViewController animated:NO];
    [loginViewController release];

and for dismissal .....

[self.window.rootViewController dismissModalViewControllerAnimated:YES];

Thanks,



回答2:

Did u release loginViewcontroller after presenting.

loginViewController = [[LoginViewController alloc]init];
        [loginViewController.view setFrame:CGRectMake(0, 0, 320, 480)];
        [self.window.rootViewController presentModalViewController:loginViewController animated:NO];
[loginViewController release];