我使用故事板拖动了一个按钮,并在.h文件中为它创建了IBoutlet也合成了它。
现在我正在尝试更改按钮的文本,但它对我不起作用。
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder]))
{
configDetails *updatedConfig=[[configDetails alloc]init];
[updatedConfig setAllItemstext:@" Go to AllItems"];
[updatedConfig setAboutUstext:@"Text for AboutUs button"];
[updatedConfig setHomeScreenTitleColor:@"Yellow"];
NSString *newtext=[updatedConfig aboutUstext];
NSLog(@"%@",newtext);
[aboutUs setTitle:[updatedConfig aboutUstext] forState:UIControlStateNormal];
[allItems setTitle:[updatedConfig allItemstext] forState:UIControlStateNormal];
}
return self;
}
答案 0 :(得分:1)
尝试将代码写入viewDidAppear
: -
-(void)viewDidAppear:(BOOL)animated{
configDetails *updatedConfig=[[configDetails alloc]init];
[updatedConfig setAllItemstext:@" Go to AllItems"];
[updatedConfig setAboutUstext:@"Text for AboutUs button"];
[updatedConfig setHomeScreenTitleColor:@"Yellow"];
NSString *newtext=[updatedConfig aboutUstext];
NSLog(@"%@",newtext);
[aboutUs setTitle:[updatedConfig aboutUstext] forState:UIControlStateNormal];
[allItems setTitle:[updatedConfig allItemstext] forState:UIControlStateNormal];
[super viewDidAppear:animated];
}
答案 1 :(得分:0)
您无法在initWithCoder
方法中设置IBOutlet属性。
请参阅我的answer了解