如何使用自定义中心按钮在 uiTabBarController 中选择选项卡
我有一个带有 TabBarController 的故事板启用应用程序,我通过界面生成器添加了视图控制器。
然后我按照 iDevReceipes 帖子添加中心的自定义按钮,它使用自定义按钮隐藏我的第三个或中心选项卡栏项目。
当用户单击按钮时,我无法使 TabBarController 选择中间选项卡。我用一个选择器连接了按钮,并在方法中添加了一个代码,该代码被认为是适用于 Stack Overflow 上许多人的解决方案,即 self.tabBarController.SelectedIndex = 2;
这在 viewWillAppear 中被
称为不知何故无法工作并选择正确的选项卡。我在按钮的方法中有一个 NSLog,我发现按钮可以工作,但选项卡没有被选择。
tabbarcontroller 有一个类,里面什么都没有。
I have a storyboard enabled App with a TabBarController where I have added viewcontrollers through the interface builder.
Then I followed the iDevReceipes post to add a custom button in the center, which hide my third or center tab bar item with a custom button.
I'm not able to make the TabBarController select the middle tab when a user clicks the button. I wired the button with a selector and within the method I added a code which was supposedly a solution which worked for many on Stack Overflow i.e self.tabBarController.SelectedIndex = 2;
this was called in viewWillAppear
This is somehow not working and selecting the correct tab. I had a NSLog inside the method of the button and I found out the button works but the tab is not getting selected.
The tabbarcontroller has a class with nothing inside this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的想法是对的,但是你需要使用setter方法,而不是直接设置属性;这是它确实产生影响的一个例子。另外,我可能会误解您,但您需要在按钮的选择器中调用此代码,而不是在
viewWillAppear
方法中。这是您将用于选择中间索引的代码。You have the right idea, but you need to use a setter method and not set the property directly; this is one instance where it does make a difference. Also, I may be misunderstanding you, but you need to call this code in the selector for the button, not in the
viewWillAppear
method. Here's the code you'll use to select the middle index.