我已经检查了许多文章,以了解在 ios 中单击 uibutton 时传递的值。但一般来说,人们使用标签属性作为替代。
但我找到了以下解决方案:
UIButton *btnComLike=[[UIButton alloc] init];
[btnComLike setFrame:CGRectMake(127, 20, 30, 15)];
[btnComLike addTarget:self action:@selector(btnCommentLike_click:) forControlEvents:UIControlEventTouchUpInside];
[btnComLike setTitle:@"Like" forState:UIControlStateNormal];
[btnComLike setTitle:@"my any string value" forState:UIControlStateReserved];
和处理程序方面:
-(void)btnCommentLike_click:(id)sender
{
NSLog(@"%@",[sender titleForState:UIControlStateReserved]);
}
这是可行的解决方案吗?我认为一个是利用这种状态UIControlStateReserved
。
或者使用这种技术有什么缺点吗?
如果是,请告诉我出了什么问题?