将UISegmentedControl添加到UINavigationController的toolBar中

时间:2013-05-22 15:18:18

标签: ios objective-c uinavigationcontroller

尝试将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,则加载正常。

我做错了什么?

0 个答案:

没有答案