3

我在表格视图单元格中添加了一个按钮。我的问题是,当我在调用方法上更改其标题时,pressHonkBtn:(id)sender它并没有更改其标题。

如何解决这个问题。

4

4 回答 4

8

像这样使用您的代码:

目标-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)

希望它可以帮助你。

于 2013-05-03T12:14:16.333 回答
1

请尝试使用这个.....它会正常工作。

-(IBAction)pressHonkBtn:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    [btn setTitle:@"title" forState:UIControlStateNormal];
}
于 2013-05-03T12:17:16.627 回答
0

试试这个:

-(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];
}
于 2013-05-03T12:27:03.493 回答
-2

由于您正在接收 id 作为参数,因此您需要将其类型转换为 UIButton 。

-(IBAction)pressHonkBtn:(id)sender
 {
    UIButton *senderBtn = (UIButton *)sender;

    [senderBtn setTitle:[NSString stringWithFormat:@"Title"] forState:UIControlStateNormal];
 }
于 2013-05-03T12:16:14.140 回答