开发者

Multiwindows problem, cocoa

开发者 https://www.devze.com 2023-03-30 04:48 出处:网络
I have a simple application, not document-based. I want to have a login window that allows people to login or add a user, and when they logged in successfully I want it to load the main page. If from

I have a simple application, not document-based. I want to have a login window that allows people to login or add a user, and when they logged in successfully I want it to load the main page. If from the main page you click log out, it should destroy the main page and take you back to login page. sounds like a simple plan, but for some reason I have a problem.

The way I have it right now, I check if the customer logged in or not in the main file AppDelegate and load different window controller. When customer logs in, I send a notification back to AppDelegate from Login Conntroller and load another window controller for main window.

Something like this:

if([[settings get:@"isLoggedIn"] isEqualToString:@"Yes"]) 
{
    MainController *tmpMainController = [[MainController alloc] initWithWindowNibName:@"MainWindow"];
    self.mainController = tmpMainController;
    NSWindow *mainWindow = [tmpMainController window];
    [mainWindow makeKeyAndOrderFront:self];
    [tmpMainController release];

}  else {
    LoginController *tmpViewController = [[LoginController alloc] initWithWindowNibName:@"LoginWindow"];
    self.loginController = tmpViewController;
    loginWindow = [tmpViewController window];
    [loginWindow makeKeyAndOrderFront:self];
    [tmpViewController release];
}

Everything works fine, it displays the correct window. But the weird part happens when I log out from the main page, log in again and log out again. If I do it several times, instead of showing me 1 login window, it draws 2. If I continue the login process, on the second try I get 2 main windows. If I log out again, I see 4 cascade login windows, then I see 5 or 7 main windows. After all windows gets loaded all extra windows start getting destroyed one-by-one. It looks like when new window gets created it draws all old windows, then the new one and then destroys all old ones. I don't know why it happens. Would like some help.

Here is the code from my main controller when customer clicks log out:

-(IBAction)logOutClick:(id) sender
{
     [settings set:@"isL开发者_如何转开发oggedIn" value:@"No"];
     [[self window] orderOut:self];
     [[NSNotificationCenter defaultCenter] postNotificationName:@"NSUserLoggedOutNotification" object: self userInfo: nil];
}

the same thing for login controller:

if ([users verifyUser]) {
        [settings set:@"isLoggedIn" value:@"Yes"];
        [loginView removeFromSuperview];
        [[self window] orderOut:self];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"NSUserLoggedInNotification" object: self userInfo: nil];
    }

I have "Released when closed" checked off for both windows.


I added new nsnotification center observer every time I log out.
That was the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消