我有一个想要出现在 UIToolbar 中的 UISegmentedControl。它出现了,但单击它不会调用它应该调用的方法。我错过了什么吗?
代码:
-(void)setupToolbars{
NSArray *segItemsArray = [NSArray arrayWithObjects: @"List", @"Day", @"Month", nil];
segmentedControl = [[UISegmentedControl alloc] initWithItems:segItemsArray];
segmentedControl.selectedSegmentIndex = 2;
[segmentedControl addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];//this line should make the segmented control call the correct method
UIBarButtonItem *segmentedControlButtonItem = [[UIBarButtonItem alloc] initWithCustomView:(UIView *)segmentedControl];
NSArray *barArray = [NSArray arrayWithObjects: todayButtonItem,flexibleSpace, segmentedControlButtonItem, flexibleSpace, nil];
[bottomToolbar setItems:barArray];
}
-(void)changeView{
NSLog(@"changeView");
...
}