2014-07-05 28 views
1

後,我有標題樂趣按鈕whitch從故事板UIButton的標題刷新UIAlertView中

在viewDidLoad中更改標題

self.catBut.titleLabel.text = @"Random"; 

然後設置時,另一個按鈕是點擊

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title alert" message:@"Alert message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
    [alert show]; 

但是提示後顯示的按鈕標題改回好玩

回答

0

.h文件中保持這種

@property(non atomic,strong)IBOutlet UIButton *catBut; 

使用這種變革的按鈕標題

[self.catBut setTitle:@"Random" forState:UIControlStateNormal]; 

使用UIAlertViewDelegate方法

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title alert" message:@"Alert message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
alert.tag==100; //if u used multiple alert in your VC, use to identify the Tag 
    [alert show]; 


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
{ 
if(alertView.tag==100) 
{ 
[self.catBut setTitle:@"Random" forState:UIControlStateNormal]; 
} 
else 
    { 
    // anotehr mthod optiobns 
} 
} 
+0

好的觸發按鈕後,再次玩轉 – Ben

+0

你當你點擊警報視圖按鈕時,需要更改按鈕標題爲「FUN」 rrect或其他任何你需要修改 –

+0

否,按鈕標題是viewDidLoad中的改變。警報後重置,但不想重置該值。該按鈕必須保持隨機 – Ben