如何从iOS中的另一个类访问标记上的按钮?
我有一个按钮:如何从iOS中的另一个类访问标记上的按钮?,ios,class,button,Ios,Class,Button,我有一个按钮: - (UIButton *)subwayABBtn { if (!_subwayABBtn) { _subwayABBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _subwayABBtn.tag = ADRESS_SUBWAY_BTN_TAG; [_subwayABBtn setTitle:@"Метро" forState:UIControlStateN
- (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;
}
如何使用另一个类中的标记更改按钮的标题?我需要更改按钮的标题。我不明白你说的另一门课是什么意思。如果它是从您的视图中添加按钮的,那么您可以使用下面的代码来获取UIButton
UIButton *btn = (UIButton *)[self.contentView viewWithTag:ADRESS_SUBWAY_BTN_TAG];
[btn setTitle:@"New title" forState:UIControlStateNormal];
使用
委托
和@protocol
访问ios中的父视图控制器
您需要对视图控制器中其他类的引用,在其头文件中声明该按钮,并使用方法
-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];
您通常使用的“另一个类”是什么