Ios 将UISegmentedControl添加到UINavigationController';工具栏
正在尝试将Ios 将UISegmentedControl添加到UINavigationController';工具栏,ios,objective-c,uinavigationcontroller,Ios,Objective C,Uinavigationcontroller,正在尝试将UISegmentedControl添加到UINavigationController的工具栏中 -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.toolbarHidden = FALSE; UIBarButtonItem *test1 = [[UIBarButtonItem alloc] initWithTit
UISegmentedControl
添加到UINavigationController
的工具栏中
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = FALSE;
UIBarButtonItem *test1 = [[UIBarButtonItem alloc] initWithTitle:@"Groups"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Groups", @"Regions", @"Objects"]];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[self setToolbarItems:[NSArray arrayWithObjects:test1, segmentedControl, nil]];
}
这会导致以下错误:
-[UISegmentedControl view]: unrecognized selector sent to instance 0x295623c0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISegmentedControl view]: unrecognized selector sent to instance 0x295623c0'
如果我省略了UISegmentedControl
,它可以正常加载
我做错了什么?您需要用类似于
[[uibarbuttoneim alloc]initWithCustomView:segmentedControl]]的东西将UISegmentedControl包装在uibarbuttoneim中。
就是这样做的!请注意,重复的问题并不完全相同,但答案是相同的。