如何禁用 UISegmentedControl?
我有以下 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 中的操作:
如何确保它不能被点击?
I have the following UISegmentedControl, which I want to be disabled:
-(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:
How can I make sure it can't be clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用:
或
Try using:
or
在
titleBarButtonChanged:(id)sender
中添加:Within
titleBarButtonChanged:(id)sender
add: