簡體   English   中英

UIAlertView之后刷新UIButton標題

[英]UIButton title refresh after 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];

但是在警報顯示后,按鈕的標題更改回Fun

.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
 }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM