【问题标题】:How to check UIButton tag is set or not如何检查 UIButton 标签是否设置
【发布时间】:2014-07-16 05:36:58
【问题描述】:

如果 UIButton 有任何标记值,我需要一个操作。

如果它没有标签值需要采取另一个行动。

我尝试过关注,但它崩溃了。

-(void)buttonClick:(id)sender {

    NSInteger t = [sender tag]; //crashing here if it has no tag value

    if(t) {
        //action
    } else {
        //another action
    }

}

【问题讨论】:

  • 什么是崩溃信息?

标签: ios objective-c uibutton


【解决方案1】:

试试这个,你必须设置 button.tag=100

if ([sender isMemberOfClass:[UIButton class]])
    {
        UIButton *btn = (UIButton *)sender;

        // Then you can reference the title or a tag of the clicked button to do some further conditional logic if you want.
        if(btn.tag==100)
        {

         }
}

【讨论】:

  • 为什么要将标签值设置为100?为什么不只做“if([sender tag] == 0)”。 @Ramesh Kumar
  • 你希望它不要强迫
猜你喜欢
  • 2016-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-08
  • 2016-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多