【问题标题】:How can I disable a UISegmentedControl?如何禁用 UISegmentedControl?
【发布时间】:2011-12-23 20:58:15
【问题描述】:

我有以下 UISegmentedControl,我想禁用它:

-(void)displayCheckMark
{
    titleSegmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
    [titleSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"symbolbg.png"] atIndex:0 animated:YES];
    [titleSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"inwatchlist.png"] atIndex:1 animated:YES];
    [titleSegmentedControl addTarget:self action:@selector(titleBarButtonChanged:)forControlEvents:UIControlEventValueChanged];
    titleSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    titleSegmentedControl.frame = CGRectMake(100,0,100,30);
    titleSegmentedControl.momentary = YES;
    titleSegmentedControl.tintColor = [UIColor blackColor];
    self.navigationItem.titleView = titleSegmentedControl;

    [titleSegmentedControl setWidth:60 forSegmentAtIndex:0];
    [titleSegmentedControl setTitle:symbol forSegmentAtIndex:0];
    [titleSegmentedControl setWidth:30 forSegmentAtIndex:1];
    [titleSegmentedControl setEnabled:NO];
}

我没有在代码的任何地方启用它。但是我仍然可以点击它,它会执行titleBarButtonChanged中的动作:

如何确保它不能被点击?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uibarbuttonitem uisegmentedcontrol


    【解决方案1】:

    尝试使用:

    - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment;
    

    titleSegmentedControl.userInteractionEnabled = NO;
    

    【讨论】:

      【解决方案2】:

      titleBarButtonChanged:(id)sender内添加:

      if(!sender.enabled) return;
      

      【讨论】:

        猜你喜欢
        • 2011-09-15
        • 1970-01-01
        • 1970-01-01
        • 2016-07-28
        • 1970-01-01
        • 2013-12-06
        • 2015-11-16
        • 2023-03-20
        • 1970-01-01
        相关资源
        最近更新 更多