ios - 如何从 iOS 中的另一个类访问标签上的按钮?

标签 ios class button

我有一个按钮:

- (UIButton *)subwayABBtn
{
    if (!_subwayABBtn)
    {
        _subwayABBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        _subwayABBtn.tag = ADRESS_SUBWAY_BTN_TAG;

        [_subwayABBtn setTitle:@"Метро" forState:UIControlStateNormal];
        [_subwayABBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        [self.contentView addSubview:_subwayABBtn];
    }

    return _subwayABBtn;
}

如何使用另一个类的标签更改按钮的标题?我需要更改按钮的标题。

最佳答案

您需要引用 View Controller 中的其他类,在其头文件中声明按钮并使用方法-viewWithTage:

示例:

OtherClass *otherClass; // This should be set from previous class and a property in your current class 
UIButton *buttonFromOtherClass = [otherClass viewWithTag:BUTTON_TAG]; 
[buttonFromOtherClass setTitle:@"Метро" forState:UIControlStateNormal];

关于ios - 如何从 iOS 中的另一个类访问标签上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14895397/

相关文章:

javascript - 按钮在 Mozilla Firefox 中不起作用,但在 Google Chrome 中不起作用

ios - 从 ViewController 转到 TabBarController 的第一个选项卡

jQuery UI - 我无法设置复选框按钮的样式

java - 如何合并和验证 swt 对话框的两个文本字段?

Python:如何定义一个行为像函数的类?

python - 如何在构造函数之前声明静态变量,以及如何在其主体中引用类?

c# - 泛型类中的可空泛型字段

ios - 如何在单击按钮时更改 tabbaritem 图像?

ios - 从端点调整线的大小

ios - 带有 UIWindowLevelStatusBar + 1 的窗口在 iOS 8 上隐藏状态栏