我在表格视图单元格中添加了一个按钮。我的问题是,当我在调用方法上更改其标题时,pressHonkBtn:(id)sender
它并没有更改其标题。
如何解决这个问题。
像这样使用您的代码:
目标-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];
}
迅速:
someUIButton.setTitle("String To Set", forState: UIControlState.Normal)
希望它可以帮助你。
请尝试使用这个.....它会正常工作。
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
[btn setTitle:@"title" forState:UIControlStateNormal];
}
试试这个:
-(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];
}
由于您正在接收 id 作为参数,因此您需要将其类型转换为 UIButton 。
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *senderBtn = (UIButton *)sender;
[senderBtn setTitle:[NSString stringWithFormat:@"Title"] forState:UIControlStateNormal];
}