使用标签控制多个按钮 [英] Control more than one button using tags
本文介绍了使用标签控制多个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有28个按钮。我需要在一个函数中控制它们。我想做的就是让所有按钮都可见。我给了按钮标签。我用for循环尝试了但是我不能这样做我怎么能解决这个问题?
I have 28 buttons in my application. I need to control them in a single function. All I want to do is make all the buttons visible. I gave tags to the buttons. I tried it with a for loop but I couldn't do it how can I solve this problem?
(IBAction)btnAction:(id)sender{
UIButton *btnPressed = (UIButton *)sender;
NSUInteger i=btnPressed.tag;
for(i=0; i<29; i++)
{
btnPressed.hidden=NO;
}
}
推荐答案
使用IBOutletCollection而不是标签。所以现在你有一个单 NSArray指向按钮的所有。现在只需循环通过NSArray。
Instead of tags, use an IBOutletCollection. So now you have a single NSArray pointing to all of the buttons. Now just cycle through that NSArray.
这篇关于使用标签控制多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文