user3650480
user3650480

Reputation: 9

display a random string in a button in objective-c

I have the following code to display a random string from my array on a button, but I can't figure out what's wrong (the declared array isn't included below). There is definitely a problem with the last line. Thanks!

             int index = [self.colorlist count];
             int random = (arc4random() % index);
             NSString *color1 = [self.colorlist objectAtIndex:random];
             [Button1 setTitle:@"%@", color1 forState:UIControlStateNormal];

Upvotes: 1

Views: 68

Answers (1)

Jason McCreary
Jason McCreary

Reputation: 73031

setTitle: accepts an NSString, not a format (@"%@", color1):

[Button1 setTitle:color1 forState:UIControlStateNormal];

Upvotes: 2

Related Questions