【问题标题】:UIButton title refresh after UIAlertViewUIAlertView 后 UIButton 标题刷新
【发布时间】:2014-07-05 10:25:34
【问题描述】:

我有一个标题为 Fun 的按钮是从情节提要中设置的

在 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

【问题讨论】:

    标签: ios objective-c uibutton uialertview uialertviewdelegate


    【解决方案1】:

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

    【讨论】:

    • Ok 被触发后按钮又是 Fun
    • 当您点击警报视图按钮时,您需要将按钮标题更改为“FUN”,更正,或者您需要修改的任何其他内容
    • 不,按钮标题在 viewDidLoad 中发生了变化。并在警报后重置但不想重置该值。按钮必须保持随机
    • 我认为我的修改答案对你来说很好?,你需要任何修改吗,我为你改变我的答案
    • setTitle 在没有 UIAlertViewDelegate 的情况下完成这项工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多