2013-12-23 37 views
0

我用故事板拖动了一个按钮,并在.h文件中为它创建了IBoutlet。更改按钮文本不起作用iOS

现在我试图改变按钮的文本,但它不适合我。

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

上面的代码是否正在执行?你有没有尝试添加一个断点? – ColinE

+0

'[updatedConfig allItemstext]'获得了价值吗? –

+0

@AnoopVaidya雅它输出giventext – iCoder

回答

0

您不能在initWithCoder方法设置你的IBOutlet中的属性。

请参阅我的answer关于此

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]; 
}