我有一个要显示在 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");
...
}
最佳答案
您想使用 UIControlEventValueChanged
事件,而不是 UIControlEventTouchUpInside
事件。
关于ios - UIButtonBarItem 中的 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17277561/