UISegmentedControl、UIToolbar 和 UINavigationItem

发布于 2024-08-16 08:57:31 字数 1477 浏览 7 评论 0原文

我已经创建了一个 UISegmentedControl 并成功将其附加到我的 navigationItem.tableView。

但是当我尝试将它附加到 UIToolbar 时,它爆炸了。

我确信我以前在工具栏上见过 UISegementedControls - 但似乎无法让它工作。想法?

// works
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil];
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems];
self.navigationItem.titleView = statusSegments_;

// doesn't work
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil];
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems];
NSArray *toolbarItems = [[NSArray alloc] initWithObjects:statusSegments_, nil];
self.toolbarItems = toolbarItems;
[toolbarItems release];
[Session started at 2010-01-01 13:40:35 -0600.]
2010-01-01 13:40:35.182 TimeSheet[15382:20b] *** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0
2010-01-01 13:40:35.183 TimeSheet[15382:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0'
2010-01-01 13:40:35.184 TimeSheet[15382:20b] Stack: (
    10847323,
    2479902267,
    11229243,
    10798710,
    10651330,
    24428622,
    24429410,
    24133352,
    24133878,
    11379,
    24149733,
    24130330,
    24151483,
    24129979,
    23770,
    23906970,
    23890136,
    2838970,
    10631872,
    10628168,
    960429,
    960626,
    23633923
)

I've create a UISegmentedControl and successfully attached it to my navigationItem.tableView.

But when I try instead to attach it to a UIToolbar, it blows up.

I'm sure I've seen UISegementedControls on toolbars before - but can't seem to get it working. Thoughts?

// works
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil];
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems];
self.navigationItem.titleView = statusSegments_;

// doesn't work
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil];
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems];
NSArray *toolbarItems = [[NSArray alloc] initWithObjects:statusSegments_, nil];
self.toolbarItems = toolbarItems;
[toolbarItems release];
[Session started at 2010-01-01 13:40:35 -0600.]
2010-01-01 13:40:35.182 TimeSheet[15382:20b] *** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0
2010-01-01 13:40:35.183 TimeSheet[15382:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0'
2010-01-01 13:40:35.184 TimeSheet[15382:20b] Stack: (
    10847323,
    2479902267,
    11229243,
    10798710,
    10651330,
    24428622,
    24429410,
    24133352,
    24133878,
    11379,
    24149733,
    24130330,
    24151483,
    24129979,
    23770,
    23906970,
    23890136,
    2838970,
    10631872,
    10628168,
    960429,
    960626,
    23633923
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的快感 2024-08-23 08:57:31

您需要将分段控件视图包装在 UIBarButtonItem 中:

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

You need to wrap the segmented control view in a UIBarButtonItem:

UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:statusSegments_] autorelease];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文