Search code examples
iphoneios5ibaction

I am using same action for 5 buttons and want to know which button is called?


I am using same action for 5 buttons and want to know which button is called


Solution

  • UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self 
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchDown];
    [button setTitle:@"Show View" forState:UIControlStateNormal];
    button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
    button.tag=1;
    [view addSubview:button];
    
    -(void)aMethod:(id)sender{
    
    UIButton *button = (UIButton *)sender;
    
    int clickedBtnTag = button.tag ;
    
    Nslog("clicked button tag is %d",clickedBtnTag);
    
    } 
    

    Try this and then please revert me..