1

I have a button with title Fun whitch is set from the storyboard

In viewDidLoad I change the title

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

And then when another button is click

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

But after the alert shows up the title of the button change back to Fun

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Ben
  • 1,906
  • 10
  • 31
  • 47

1 Answers1

0

.h file keep this

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

use this for change the button title

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

use UIAlertViewDelegate Method

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
 }
 }
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143