2013-12-23 39 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]; 
}