我创建一个按钮并将标题设置为"单击此处".当我按下该按钮时,我想获得该按钮标题并记录下来.这是我的代码,我哪里错了?
-(void)clicketbutton { UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeCustom]; [mybutton setTitle:@"Click here" forState:UIControlStateNormal]; [mybutton addTarget:self action:@selector(displayvalue:)forControlEvents:UIControlEventTouchUpInside]; } -(void)displayvalue:(id)sender { UIButton *resultebutton= [UIButton buttonWithType:UIButtonTypeCustom]; resultebutton=sender;// pls clear here.. my question here , it it possible or not. if possible how ? NSLog(@" The buttontitile is %@ ", [resultebutton.Title] // here also. }
Harry Lachen.. 72
你的displayvalue:方法应该是这样的:
-(void)displayvalue:(id)sender { UIButton *resultButton = (UIButton *)sender; NSLog(@" The button's title is %@.", resultButton.currentTitle); }
(请查看XCode中的文档,它会给你正确的答案.)
你的displayvalue:方法应该是这样的:
-(void)displayvalue:(id)sender { UIButton *resultButton = (UIButton *)sender; NSLog(@" The button's title is %@.", resultButton.currentTitle); }
(请查看XCode中的文档,它会给你正确的答案.)
-(void)displayvalue:(id)sender { UIButton *resultebutton= (UIButton*)sender; NSLog(@"The button title is %@ ", resultebutton.titleLabel.text); }