从 UIViewController 方法更改 UIWindow 的呈现视图

发布于 2024-11-03 11:06:48 字数 591 浏览 4 评论 0原文

我有一个简单的应用程序,其中包含 UIViewController 的两个子类。

我想通过调用 UIViewController 子类之一的方法来更改应用程序的 UIWindow 显示的视图。

本质上,我只是在乱搞,我正在尝试构建一个带有登录屏幕的简单测试应用程序,在用户输入凭据后会显示一个主视图。我不太熟悉iOS编程的窗口和视图机制,我目前正在阅读 http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW1 并尝试了解一些相关知识。

I have a simple application with two subclasses of UIViewController.

I want to change the view being displayed by my application's UIWindow by calling a method from one of my UIViewController subclasses.

Essentially I'm just messing around and I'm trying to construct a simple test application with a login screen, that after a user enters credentials a main view is presented. I'm not too familiar with the window and view mechanisms of iOS programming, and I'm currently reading http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW1 and attempting to learn a bit about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身软味 2024-11-10 11:06:48

如果这是为了登录屏幕,您应该直接将主视图控制器添加到窗口,并将登录视图控制器添加为主视图控制器内的模式视图。

在 applicationDidFinishLaunching 内部...

MainViewController *mainViewController = [[MainView....... // instantiate UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:mainViewController];
[mainViewController release]; 
[window addSubview:navController.view];

在 MainViewController 内部

-(void)viewWillAppear:(BOOL)animated
{
    LoginViewController *loginVC = .... //instantiate
    [self.navigationController presentModalViewController:loginVC  animated:NO];
    [loginVC release];
}

如果登录成功,

[self dismissModalViewControllerAnimated:YES];

If this is for the purpose of a login screen, you should add the main view controller to window directly, and add the login view controller as a modal view inside the main view controller.

Inside applicationDidFinishLaunching...

MainViewController *mainViewController = [[MainView....... // instantiate UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:mainViewController];
[mainViewController release]; 
[window addSubview:navController.view];

Inside MainViewController

-(void)viewWillAppear:(BOOL)animated
{
    LoginViewController *loginVC = .... //instantiate
    [self.navigationController presentModalViewController:loginVC  animated:NO];
    [loginVC release];
}

if login successful,

[self dismissModalViewControllerAnimated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文