简体   繁体   English

在iOS iPhone中难以显示选项卡视图

[英]Difficulty displaying Tab Views in iOS iPhone

I'm new to iOS dev and I have a program that begins by presenting the user a view. 我是iOS开发人员的新手,我有一个程序开始于向用户展示视图。 This view has two buttons, and depending on which the user clicks, a different tab view will be displayed. 该视图有两个按钮,根据用户单击的内容,将显示不同的选项卡视图。 The tab view is displayed like this: 标签视图显示如下:

betaAppDelegate* delegate = (betaAppDelegate*)[[UIApplication sharedApplication]delegate];
acquireData *ac_view = (acquireData*)[[acquireData alloc] init];
[delegate.window addSubview:ac_view.view];

[self.view removeFromSuperview];
[self dealloc];

The tab view is ac_view.view. 选项卡视图是ac_view.view。 When I run the application in the simulator, instead of displaying my tab view with three tabs, it displays a white screen with a thin black bar (empty tab dock) on the bottom. 当我在模拟器中运行应用程序时,它没有显示带有三个选项卡的选项卡视图,而是在底部显示了带有细黑条(空白选项卡底座)的白屏。 It's encouraging to at least see something be displayed! 至少看到一些令人鼓舞的东西是令人鼓舞的! But I've been trying without success for a while to get it to display my tabs. 但是一段时间以来,我一直在尝试使它显示我的标签没有成功。 The .xib file looks correct. .xib文件看起来正确。 It has the three tabs at the bottom, and each of the three tabs say in the interface builder that they're loaded from xxxxxxx, so the linking appears correct... 它在底部具有三个选项卡,并且三个选项卡中的每个选项卡在界面生成器中都说它们是从xxxxxxx加载的,因此链接显示正确...

Thank you! 谢谢!

I'm going to presume you're using the UITabBarController. 我假设您正在使用UITabBarController。

You can either set one up by adding the tabs in interface builder and then setting which xibs the individual tabs load up. 您可以通过在界面构建器中添加选项卡来设置一个选项卡,然后设置各个选项卡要加载的选项卡。 It sounds like you have done this. 听起来您已经做到了。 After that there is no code you need to write to get the tab bar working to switch between your three view controllers. 之后,您无需编写任何代码即可使选项卡栏正常工作以在三个视图控制器之间切换。

You can also set up the TabBarController programatically. 您还可以通过编程方式设置TabBarController。

This would be the programmatic way and would go into you application delegate 这将是编程方式,并将进入您的应用程序委托中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UITabBarController * aTabBarController = [[UITabBarController alloc] init];
NSArray * array = [[NSArray alloc] initWithObjects:controller1, controller2, controller3, nil];
[aTabBarController setViewControllers:array animated:NO];
[array release];

self.window.rootViewController = aTabBarController;
[self.window makeKeyAndVisible];
[aTabBarController release];
return YES;
}

You would then see a tab bar with three tabs that correspond to controller1, 2 and 3 (your custom view controllers) 然后,您将看到一个带有三个选项卡的选项卡栏,分别对应于controller1、2和3(您的自定义视图控制器)

To set the icon and text and things its as easy as reading the documentation and seeing 设置图标和文本及其内容就像阅读文档一样容易

Tab bar items are configured through their corresponding view controller. 标签栏项目通过其相应的视图控制器进行配置。 To associate a tab bar item with a view controller, create a new instance of the UITabBarItem class, configure it appropriately for the view controller, and assign it to the view controller's tabBarItem property. 要将选项卡栏项与视图控制器相关联,请创建UITabBarItem类的新实例,为视图控制器进行适当配置,然后将其分配给视图控制器的tabBarItem属性。

Just a final word of warning in Objective C you should never call dealloc yourself. 在目标C中,最后的警告是,您永远不要称自己为dealloc。 Dealloc is called by the system when an objects retain count reaches 0. Read into how to retain and release objects to get the hang of how this all works. 当对象的保留计数达到0时,系统会调用Dealloc。了解如何保留和释放对象,以了解所有工作原理的本质。

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM