多视图应用程序

时间:2009-12-28 15:09:01

标签: iphone

我正在努力开发一个工程项目。我的第一个视图有一个文本字段,用户需要输入“e”或“s”表示要使用的单位(英语或si),它存储在变量es中。 AppDelegate通过applicationDidFinishLaunching:方法显示第一个视图。我有一个Objective-C源文件,我正在编写代码。如何使用许多文本字段加载下一个视图,其中用户必须输入一些值以保存在变量中?

1 个答案:

答案 0 :(得分:0)

最简单的方法是在App Delegate上构建导航控制器。然后,您可以轻松地将视图推入和关闭Controller。这样的事情(这在你的App Delegate的applicationDidFinishLaunching内很好用):

// controller is defined in the header
controller = [[UINavigationController alloc] init];
controller.navigationBar.barStyle = UIBarStyleBlack;
...
// Build your UIView
SomeUIView *welcome = [[SomeUIView alloc] initWithNibName: @"Welcome" bundle: nil];
[controller pushViewController: welcome animated: NO];
[welcome release];
...
// Display the Controller's top view in the window
[window addSubview: controller.view];
[window makeKeyAndVisible];

然后更改视图(此代码适用于您的应用程序中的任何位置):

SomeOtherView *Detail = [[SomeOtherView alloc] initWithNibName:@"Detail" bundle:nil];
[self.navigationController pushViewController: Detail animated:YES];
[Detail release];

请注意,您始终可以通过“self”返回导航控制器。

好舔!