我如何知道此按钮用于操作的类别?

时间:2017-09-21 15:12:27

标签: ios objective-c

我如何知道此按钮用于操作的类别?
当我触摸按钮然后执行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?");
}

1 个答案:

答案 0 :(得分:0)

你可以用于比较 -

- (IBAction) touchButton:(id)sender {

    UIButton *btn = (UIButton *) sender;

   if([btn.class isMemberOfClass:<#(__unsafe_unretained Class)#>]){
     /// write your code here....
   }

}