ios - UIButtonBarItem 中的 UISegmentedControl

标签 ios objective-c uitoolbar uisegmentedcontrol uibuttonbaritem

我有一个要显示在 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/

相关文章:

objective-c - 使用Objective-C,什么情况下需要手动进行内存管理?

iphone - HTML 未正确加载

iphone - iOS 5.0 模态视图不旋转( Storyboard)

ios - UIToolbar 动画 alpha ios7

iphone - 我可以淡化/动画 UIToolbar 的 tintColor 吗?

ios - 如何将 DeviceMotion 功能添加到 Swift Playground?

ios - UICollectionView 标题宽度

ios - 如果关系链中对象的属性发生更改,如何通知 NSFetchRequestController

swift - 根据 UITextView 内容快速禁用/启用 UIBarButtonItem

iphone - UIScrollView 中的 JSON 图像