我如何从发件人获取标记值

时间:2022-10-20 21:12:40
- (IBAction)onClick1:(id)sender {
    // Make sure it's a UIButton
    if (![sender isKindOfClass:[UIButton class]])
        return;

    NSString *title = [(UIButton *)sender currentTitle];
}

I understand how to get the title and other current values but I don't see how I can get the value of the tag property.

我知道如何获取标题和其他当前值,但我不知道如何获取tag属性的值。

2 个解决方案

#1


43  

I've got a test project here where I just used:

我在这里使用了一个测试项目:

NSInteger i = [sender tag];

#2


3  

You can simply call:

你可以简单地打电话:

NSInteger the_tag = ((UIView*)sender).tag;

Each UIButton is a subclass of UIView which contains the tag property.

每个UIButton都是UIView的子类,它包含tag属性。

#1


43  

I've got a test project here where I just used:

我在这里使用了一个测试项目:

NSInteger i = [sender tag];

#2


3  

You can simply call:

你可以简单地打电话:

NSInteger the_tag = ((UIView*)sender).tag;

Each UIButton is a subclass of UIView which contains the tag property.

每个UIButton都是UIView的子类,它包含tag属性。