我有一个按钮:
- (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/