UISegmentedControl,UIToolbar和UINavigationItem [英] UISegmentedControl, UIToolbar and UINavigationItem

查看:104
本文介绍了UISegmentedControl,UIToolbar和UINavigationItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我确定我之前在工具栏上看过UISegementedControls - 但似乎无法让它工作。想法?

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
)


推荐答案

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

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

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

这篇关于UISegmentedControl,UIToolbar和UINavigationItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆