更改 UITabBar 选定选项卡
我有一个作为选项卡栏应用程序创建的应用程序,有 3 个选项卡(主页、搜索、我的帐户)。主页视图加载了一些信息和一个搜索按钮。然后,搜索按钮会将用户带到搜索视图,但由于用户没有选择该选项卡,因此所选选项卡仍然是“主页”选项卡。搜索 viewDidLoad 后,如何将所选选项卡从“主页”更改为“搜索”?
I have an app that I created as a Tab Bar Application, and there are 3 tabs (Home, Search, My Account). The Home view loads with some info and a search button. The search button then takes the user to the Search View, but since the user didn't select the tab the selected tab is still the Home tab. How do I change the selected tab from the Home to the Search once the Search viewDidLoad?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
感谢您的帮助,你们帮助我朝正确的方向前进,我最终使用应用程序委托来访问 UITabBarController。这就是它的样子。
Thanks for the help, You guys helped me in the right direction I ended up using the App delegate to access the UITabBarController. This is what it looked like.
阅读文档。在搜索控制器中,您可以调用:
UITabBarController
还有一个selectedIndex
属性(如果这对您来说更方便的话)。不过,viewDidLoad
可能是放置此代码的错误位置,因为它可能不会在每次显示搜索控制器时都被调用。您应该直接从用户点击主屏幕上的搜索按钮时调用的操作内部选择选项卡。Read the documentation. From within the search controller, you can call:
UITabBarController
also has aselectedIndex
property if that's more convenient for you.viewDidLoad
is probably the wrong place to put this code in, though, as it might not be called every time the search controller is displayed. You should rather select the tab directly from inside the action that is called when the user taps the search button on the home screen.使用 tabBarController.selectedIndex = intIndex; // 在你的情况1中,
在applicationDidLaunch中使用此代码
Use tabBarController.selectedIndex = intIndex; // inyour case 1
use this code inside applicationDidLaunch
此代码片段适用于 iOS7 和 Xcode 5 的故事板。
This snippet works for me within storyboards on iOS7 and Xcode 5.