带有 UITabViewController 的 Xcode Storyboard - 从按钮更改选项卡
我有一个使用 Storyboard 的项目设置,其中包含 UITabViewController 作为初始根视图。其中一个选项卡会加载一个 NavigationController,而该 NavigationController 又会加载一个自定义视图控制器类。
在自定义视图控制器中,我有一个导航栏按钮,我想触发一个操作,将根 UITabViewController 返回到它的第一个索引。我已经能够使用传统的 xib 结构来完成此操作,方法是将 appDelegate 类添加到 xib 并以这种方式将方法链接到按钮。
实际上,我希望按钮触发如下所示的代码:
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController=_tabBarController;
-(IBAction)handleHome:(id)sender{
//How do I send a message to the tabBarController?
[self.tabBarController setSelectedIndex:0];
}
是否可以使用 Storyboard 方法来做到这一点?我查看了 Segue,但这似乎不是我想要做的(从我所看到的情况来看,我无法与根 UITabViewController 进行对话)。
我已经使用 Responder 方法触发了 handeHome 方法,因此我实际上需要知道的是如何访问 Storyboard 中实例化的 tabViewController。
希望这个问题有意义,让我知道是否有什么我应该扩展的。
I've got a project setup using a Storyboard that contains a UITabViewController as the initial root view. One of the tabs loads a NavigationController that in turn loads a custom view controller class.
From the custom view controller, I have a navigation bar button that I want to trigger an action that returns the root UITabViewController to it's first index. I've been able to do this using a traditional xib structure by adding the appDelegate class to the xib and linking a method to the button that way.
Effectively, I want the button to trigger code that looks something like this:
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController=_tabBarController;
-(IBAction)handleHome:(id)sender{
//How do I send a message to the tabBarController?
[self.tabBarController setSelectedIndex:0];
}
Is it possible to do this with the Storyboard approach? I looked at Segue's but that doesn't seem to be what I'm trying to do (there is no way for me to talk to the root UITabViewController from what I can see).
I've got the handeHome method being triggered using the Responder approach, so really all I need to know is how to access the instantiated tabViewController in the Storyboard.
Hopefully this question makes sense, let me know if there is anything I should expand on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在自定义视图控制器中执行此操作?
tabBarController
属性内置于UIViewController
中。Why not just do this in your custom view controller?
The
tabBarController
property is built in toUIViewController
.我想通了。我将引用的代码块更新为:
叹气...在询问有关 SO 的问题之前需要更多咖啡
I figured it out. I updated the quoted block of code to this:
Sigh... need more coffee before asking questions on SO