在我当前的项目中,我有一个文本字段和两个按钮。
我想用我在文本字段中键入的文本更改最后触摸的按钮的标题。
例如:->触摸按钮1在文本字段中写入例如"myButton1“-> button1标题更改为"myButton1”->然后触摸按钮2在同一文本字段中写入例如"anotherButton“-> button2标题更改为"anotherButton”
所以问题是:如何根据最后被触摸的按钮来更改文本字段的操作消息的接收者?
发布于 2015-08-19 02:34:55
您应该为两个按钮创建捕捉触摸事件的IBAction:
/// tap on button 1
- (IBAction)onBtn1Tapped:(id)sender
{
_textfield.text = @"myButton1";
UIButton * btn1 = (UIButton *)sender;
[btn1 setTitle:@"myButton1" forState:UIControlStateNormal];
}
/// tap on button 2
- (IBAction)onBtn2Tapped:(id)sender
{
_textfield.text = @"anotherButton";
UIButton * btn2 = (UIButton *)sender;
[btn2 setTitle:@"anotherButton" forState:UIControlStateNormal];
}
https://stackoverflow.com/questions/32085584
复制