objective-c 我如何从发件人那里获取标签值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1422620/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:12:13  来源:igfitidea点击:

How I get the tag value from the sender

iphoneobjective-ciphone-sdk-3.0

提问by amok

- (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.

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

回答by Rob

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

我在这里有一个我刚刚使用的测试项目:

NSInteger i = [sender tag];

回答by fbrereto

You can simply call:

您可以简单地调用:

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

Each UIButton is a subclass of UIView which contains the tagproperty.

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