以编程方式按下Xcode中的UITabBar按钮 [英] Programmatically pressing a UITabBar button in Xcode

查看:114
本文介绍了以编程方式按下Xcode中的UITabBar按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起的新手问题。我在我的主窗口视图中有一个UITabBar以及每个选项卡的UINavigationControllers数组。该结构类似于iPod应用程序,通过选择TabBar项目可以看到主视图,然后用户可以通过将视图推送到堆栈进一步向下钻取。



我想要做的就是在代码中的任何子视图中执行相当于按下TabBar按钮(即,更改TabBar的选定属性并显示启动第一个视图控制器



任何帮助将非常感谢。

解决方案

  [myTabBarController setSelectedIndex:index] 

编辑:从注释中回答第2部分的问题:



您可以在AppDelegate中定义一个方法, 。



您可以从任何地方获取appdelegate并发送消息。
类似:

  MyAppDelegate * appDelegate =(MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
[appDelegate SwitchToTab:index]


Sorry for the newbie question. I have a UITabBar in my main window view as well as an array of UINavigationControllers for each Tab. The structure is similar to the iPod app in that the main views can be seen by selecting TabBar items and then the user can drill down further with the NavigationController by pushing views to the stack.

What I would like to be able to do is to do the equivalent of pressing a TabBar button at the bottom from any of the subviews in code (i.e., change the selected property of the TabBar and display launch the first view controller for the tab).

Any help would be greatly appreciated.

Dave

解决方案

[myTabBarController setSelectedIndex:index]

EDIT: Answering the part 2 question from the comment:

You can define a method in AppDelegate for switching to a different tab.

And you can get hold of appdelegate from anywhere and send a message.. something like:

 MyAppDelegate *appDelegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];
 [appDelegate SwitchToTab:index]

这篇关于以编程方式按下Xcode中的UITabBar按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆