Reputation: 1038
I have added a button in tableview cell. My problem is this when I change its title on calling method pressHonkBtn:(id)sender
it's not changing its title.
How to solve this.
Upvotes: 3
Views: 4136
Reputation: 9913
Use your code as this :
Objective-C:
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *tempBtn = (UIButton *)sender;
[tempBtn setTitle:@"YOUR_TITLE" forState:UIControlStateNormal];// YOUR_TITLE is your button title
[tempBtn setTitle:@"YOUR_TITLE" forState:UIControlStateHighlighted];
}
Swift:
someUIButton.setTitle("String To Set", forState: UIControlState.Normal)
Hope it helps you.
Upvotes: 8
Reputation: 1730
Try this:
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[btn setTitle:@"title" forState:UIControlStateNormal];
[btn setTitle:@"title" forState:UIControlStateHighlighted];
}
Upvotes: 0
Reputation: 17535
Please try to use this one.....It will work fine.
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
[btn setTitle:@"title" forState:UIControlStateNormal];
}
Upvotes: 1
Reputation: 2145
Since your are recieving the id as argument you need to type cast it to UIButton .
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *senderBtn = (UIButton *)sender;
[senderBtn setTitle:[NSString stringWithFormat:@"Title"] forState:UIControlStateNormal];
}
Upvotes: -2