在cell 里  写button  为什么  没有点击效果  一点反映没有??- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{        actionBtn = [[UIButton alloc]init];
        actionBtn.frame = CGRectMake(210, 75, 100, 30);
        [actionBtn setBackgroundImage:[UIImage imageNamed:@"commonMiddleBt.png"] forState:UIControlStateNormal];
        [actionBtn setBackgroundImage:[UIImage imageNamed:@"commonMiddleBt_on.png"] forState:UIControlStateHighlighted];
        
        [actionBtn addTarget:self action:@selector(docking:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:actionBtn];
}
点击button 一点效果没有啊。。

解决方案 »

  1.   

    我的做法是在customcell.h定义:
    @property (nonatomic,retain) UIButton * actionBtn;
    然后在cell实例化时再:
     [cell.actionBtn addTarget:self action:@selector(docking:) forControlEvents:UIControlEventTouchUpInside];
      

  2.   

    可以按楼上的方法,使用属性,避免button在arc下被提前释放的可能
    再者就是创建button的代码放到这个方法中比较合适
    -(void)layoutSubview
      

  3.   

    你这个是 自定义的 cell ..在初始化的时候 添加 UIButton 吧为什么你设置 actionBtn.frame = CGRectMake(210, 75, 100, 30);  要 210,75 这么大的 origin.x, y 值...你这个自定义的 cell 到底有多大? 还是你设置错误了..  [self.contentView addSubview:actionBtn]; 这里你加入了 自定义 cell.contentView 里面 ..你把  actionBtn.frame = CGRectMake(10, 10, 100, 30);    试试...
      

  4.   

    谢谢各位   这个问题 已经解决了!!-(void)layoutSubview{[super layoutSubview];}
    在这个方法里 加了句这个 就成了我这个 cell是比较大  因为  这个样式