开发者

OSX: Changing parent view from subview

Right now when my application loads, it loads a login view

    LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
    [mainView addSubview:[loginViewController view]];

So after a user clicks login, I need to change the mainView. What would be the best way to go about this? How can I access the mainView from my LoginViewController?

Edit: I've c开发者_Go百科hanged my button action to release itself from the parent view, but it doesn't seem to load the next view I want to load.

- (IBAction)login:(id)sender {
NSLog(@"Pressed login button");

[[self view] removeFromSuperview];

TimerViewController *timerViewController = [[TimerViewController alloc] initWithNibName:@"TimerView" bundle:nil];
[[[self view] superview] addSubview:[timerViewController view]];
}


You could either do it in the opposite order, add the TimerViewController to the superview before removing your login view from the superview, or create a LoginViewDelegate protocol that the main view subscribes too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜