我如何知道此按钮用于操作的类别?
当我触摸按钮然后执行touchButton方法时,我想知道这个按钮在哪个类中?
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(200, 400, 100, 100);
button.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(touchButton)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)touchButton{
NSLog(@"How do I know which class this button is in for the action?");
}
答案 0 :(得分:0)
你可以用于比较 -
- (IBAction) touchButton:(id)sender {
UIButton *btn = (UIButton *) sender;
if([btn.class isMemberOfClass:<#(__unsafe_unretained Class)#>]){
/// write your code here....
}
}