【问题标题】:How to use a segmented control in the toolbar to switch views?如何使用工具栏中的分段控件来切换视图?
【发布时间】:2011-11-18 01:27:09
【问题描述】:

正如人们多次询问的那样,我正在尝试通过正确使用分段控件来切换视图。我不能只是隐藏/显示,因为视图太复杂了。

我已经使用来自this answerthis solution 让它工作,但这会将分段控件放在标题栏中。 我想把它放在底部的工具栏中。

我尝试通过 IB 连接它并声明每个子视图控件,但没有运气。我认为这与@selector 部分有关。

有人可以帮我解释一下吗?

【问题讨论】:

标签: objective-c ios uiviewcontroller selector uisegmentedcontrol


【解决方案1】:

UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:segmentedControl] autorelease];

// 如果你在导航控制器中:

[self.navigationController setToolbarHidden:NO];
self.toolbarItems = [NSArray arrayWithObject:item];

// 否则,在视图底部创建一个名为 toolBar 的 UIToolBar 并...

toolBar.items = [NSArray arrayWithObject:item];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 2011-09-07
    • 2012-03-13
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多