如何设置UIButton标签是否已设置

时间:2014-07-16 05:36:59

标签: ios objective-c uibutton

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

如果没有标签值,则需要采取其他措施。

我尝试过以下但是它崩溃了。

-(void)buttonClick:(id)sender {

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

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

}

1 个答案:

答案 0 :(得分: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)
        {

         }
}
相关问题