在 Xcode 中以编程方式按下 UITabBar 按钮

2023-06-12移动开发问题
1

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

问题描述

抱歉新手问题.我的主窗口视图中有一个 UITabBar 以及每个选项卡的 UINavigationControllers 数组.该结构类似于 iPod 应用程序,主要视图可以通过选择 TabBar 项目来查看,然后用户可以通过将视图推送到堆栈来使用 NavigationController 进一步深入.

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.

我想要做的是相当于从代码中的任何子视图按下底部的 TabBar 按钮(即,更改 TabBar 的 selected 属性并显示启动第一个视图控制器选项卡).

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).

任何帮助将不胜感激.

戴夫

推荐答案

[myTabBarController setSelectedIndex:index]

从评论中回答第 2 部分的问题:

Answering the part 2 question from the comment:

您可以在 AppDelegate 中定义一个方法来切换到不同的选项卡.

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

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

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 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7