xcode 如何检查我的按钮是否被选中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24546343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check if my button is selected?
提问by doc92606
If my button is in the "selected" state, I want an activity indicator to appear to let the user know that something is happening and that my app is searching for data. I've tried to accomplish this FIRST by using NSLog to see if I can get this method working FIRST. So I did this:
如果我的按钮处于“选定”状态,我希望出现一个活动指示器,让用户知道发生了一些事情并且我的应用程序正在搜索数据。我已经尝试通过使用 NSLog 来首先完成此操作,以查看是否可以首先使用此方法。所以我这样做了:
- (void)viewDidLoad
{
[super viewDidLoad];
searchedItem.delegate = self;
if(searchButton.selected == YES)
{
NSLog(@"The button was selected");
}
}
For some reason, it won't work.
出于某种原因,它不起作用。
回答by Kirit Modi
Put this checkmark in your button click event. It perfect work when click on button as first time then got to Not Selectedand after click on second time go to Selected.
将此复选标记放在您的按钮单击事件中。当第一次单击按钮然后转到Not Selected并在第二次单击后转到 Selected时,它完美地工作。
-(IBAction)ClickBtn:(UIButton *)sender
{
sender.selected = ! sender.selected;
if (sender.selected)
{
NSLog(@" Not Selected");
}
else
{
NSLog(@" Selected");
}
}
回答by Velu Loganathan
try this
尝试这个
- (void)viewDidLoad
{
[super viewDidLoad];
searchedItem.delegate = self;
[searchButton setSelected:YES];
if(searchButton.selected == YES)
{
NSLog(@"The button was selected");
}
}