关于 UITabBar 控制器的问题
你好,我对 iPhone sdk 完全陌生。 我正在尝试构建一个应用程序,该应用程序显示欢迎屏幕 3 秒,然后切换到具有选项卡栏视图的主应用程序屏幕。 当单独测试时,我的欢迎屏幕工作正常。但在 main.xib 中配置 UITabBarController 后,欢迎屏幕未显示。虽然标签栏工作正常。
我将欢迎屏幕的控制器命名为 rootController。 在 AppDeligate 中,我有以下代码 -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
RootController* rootController = [[RootController alloc] init];
// [self.window insertSubview:rootController.view atIndex:4];
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
显示欢迎屏幕后,我将删除其视图,并希望显示由选项卡栏组成的主视图。可能的错误是什么?
Hello Im completely new to iPhone sdk.
Im trying to build an app that shows a welcome screen for 3seconds then it switches to the main app screen which has a tab bar view.
My welcome screen is working fine when tested in isolation. But after configuring the UITabBarController in the main.xib the welcome screen is not shown. Though Tab Bar works properly.
The controller for welcome screen I've named as rootController.
In AppDeligate I've the following code -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
RootController* rootController = [[RootController alloc] init];
// [self.window insertSubview:rootController.view atIndex:4];
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
After the welcome screen is shown I'll remove its view and I expect the main view consisting of tab bar to be shown. What could be the possible error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜想标签栏控制器的视图是在 applicationDidFinishLaunching... 方法返回后加载的,因此在添加 RootController 的视图(现在位于标签栏视图下方)之后,它将添加到您的应用程序窗口中。
可能有多种方法可以实现您想要的效果,但我会在选项卡栏控制器的 viewDidLoad 方法中以模态方式呈现欢迎视图。尽管您需要为此创建标签栏视图控制器类的子类,但代码将是最容易理解的。
子类 UITabBarController,在 nib 文件中使用它,并重写 viewDidLoad 并执行类似
[super viewDidLoad] 的操作;
//创建一个RootController对象
[自我呈现ModalViewController:welcomeViewController动画:否];
您可以在需要时关闭模态视图。
I guess the view of the tab bar controller is loaded after applicationDidFinishLaunching... method returns, so it will be added to your application window AFTER you added the view of RootController, which is now beneath the tab bar view.
There could be multiple ways to achieve what you want, but I would present the welcome view modally, in viewDidLoad method in the tab bar controller. Although you need to subclass The tab bar view controller class for this, the code will be the easiest to understand.
Subclass UITabBarController, use it in the nib file,and override viewDidLoad and do something like
[super viewDidLoad];
//make a RootController object
[ self presentModalViewController:welcomeViewController animated:NO];
You will dismiss the modal view when you want.
最简单的方法:将欢迎视图控制器和选项卡栏控制器添加到 mainwindow.xib 中,为它们创建出口并将它们链接起来。
然后只显示它们:
在您的welcomeViewController中,您可以将其视图设置为3秒后隐藏,将其从窗口中删除等。
Easiest way: add both the welcome view controller and the tabbar controller to your mainwindow.xib, create outlets for them and link them up.
Then just show them both:
In your welcomeViewController you can then set its view to hidden after 3 seconds, remove itself from the window, etc.
我非常巧妙地解决了这个问题。我使用了presentModalViewController:animated:并在timerDidRan:方法中关闭了。虽然我继承了
UIViewController
而不是UITabBarcontroller
,但我觉得更正确。I solved the problem very neatly. I used
presentModalViewController:animated:
and dismissed intimerDidRan:
method. Though I subclassedUIViewController
and notUITabBarcontroller
which I feel is more correct.