Ios 目标-c如何修改与按下按钮不同的按钮文本

Ios 目标-c如何修改与按下按钮不同的按钮文本,ios,objective-c,button,Ios,Objective C,Button,如果文本是相同的方法,但我想从不同的方法更改文本,那么我将使用此方法来更改文本 -(IBAction)StartTimer:(id)sender { [sender setTitle:@"Stop" forState:UIControlStateNormal]; } -(IBAction)ResetAllData:(id)sender { [(NEED THIS PIECE) setTitle:@"Start" forState:UIControlStateNormal];

如果文本是相同的方法,但我想从不同的方法更改文本,那么我将使用此方法来更改文本

-(IBAction)StartTimer:(id)sender {
     [sender setTitle:@"Stop" forState:UIControlStateNormal];
}
-(IBAction)ResetAllData:(id)sender {
      [(NEED THIS PIECE) setTitle:@"Start" forState:UIControlStateNormal];
}

有几种方法可以做到这一点。也许最简单的方法是为另一个按钮创建一个IBOutlet,给它一个名称,比如说,另一个按钮,将它附加到故事板中,然后直接调用它,如下所示:

-(IBAction)ResetAllData:(id)sender {
      [anotherButton setTitle:@"Start" forState:UIControlStateNormal];
}
-(IBAction)ResetAllData:(id)sender {
      [[self viewWithTag:123] setTitle:@"Start" forState:UIControlStateNormal];
}
另一种方法是将标记*添加到相关按钮,例如123,然后通过其数字标记引用它,如下所示:

-(IBAction)ResetAllData:(id)sender {
      [anotherButton setTitle:@"Start" forState:UIControlStateNormal];
}
-(IBAction)ResetAllData:(id)sender {
      [[self viewWithTag:123] setTitle:@"Start" forState:UIControlStateNormal];
}
*若要添加标记,请选择界面生成器中的按钮,打开其属性,找到标记,然后在文本字段中键入所需的值。

如果要更改类属性的标题,请单击UIButton,然后您将可以直接访问它。例如,可以将以下内容放入ViewController的.m文件中

然后在您的第一个iAction中,只需设置otherButton的标题


您可能已经有了另一个按钮的IBOutlet。使用它。