[英]How can I disable a UISegmentedControl?
I have the following UISegmentedControl, which I want to be disabled:我有以下 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];
}
I don't have it enabled anywhere in the code.我没有在代码中的任何地方启用它。 Yet I can still click on it, and it will perform the action in titleBarButtonChanged:但是我仍然可以点击它,它会在 titleBarButtonChanged 中执行操作:
How can I make sure it can't be clicked?我怎样才能确保它不能被点击?
Try using:尝试使用:
- (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment;
or或者
titleSegmentedControl.userInteractionEnabled = NO;
在titleBarButtonChanged:(id)sender
添加:
if(!sender.enabled) return;
I have the following UISegmentedControl, which I want to be disabled:我有以下要禁用的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];
}
I don't have it enabled anywhere in the code.我没有在代码中的任何地方启用它。 Yet I can still click on it, and it will perform the action in titleBarButtonChanged:但是我仍然可以单击它,它将在titleBarButtonChanged中执行操作:
How can I make sure it can't be clicked?如何确保无法单击它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.