各位大神 我动态添加到View上面N个button,但是有个问题在处理他的点击事件的时候如何能判断他的动态点击事件?
- (void)terminalCreateView{    UIView *tView = [[UIView alloc]initWithFrame:CGRectMake(0, kScActionHeight- 49, kScActionWidth, 49)];
        tView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:tView];
    self.tArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < _tArray.count; i++) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button = [[UIButton alloc] initWithFrame:CGRectMake(i * kScActionWidth/(_tArray.count),0, kScActionWidth/(_tArray.count), 49)];
        _button.tag = 2015+i;
        [_button addTarget:self action:@selector(button_click:) forControlEvents:UIControlEventTouchUpInside];
            [tView addSubview:_button];
        tView.userInteractionEnabled = YES;
}
    
    [_tArray addObject:tView];
   
}
//点击事件
- (void)button_click:(UIButton *)bth
{
}

解决方案 »

  1.   

    你的_button.tag = 2015+i;不是已经把他们分开了吗点击事件又把button给传过去了 
      

  2.   

    每个button应该都有一个类似唯一id的东西。区分。
      

  3.   

    通过 button.tag ,用if判断或switch
      

  4.   

    [self.view viewWithTag:]后面加上你给btn·tag赋上的值就能拿到tag对应的控件
      

  5.   

    每个button的tag值是固定的了 根据tag值判断点击的哪个button
      

  6.   

    button.tag
      

  7.   

    button.tag 
      

  8.   

    tag,用他来判断是哪个按钮点击的