在自定义单元格中的按钮中设置标签时出现异常

时间:2014-01-04 11:29:22

标签: ios objective-c uitableview uibutton

我已将方法cellForRowAtIndexPath中的标记设置为

cell.noOfCommentsButton.tag=indexPath.row;其中noOfCommentsButton是我的UIButton。

我已将此按钮的IBAction定义为:

- (IBAction)showComments:(BlogCell *)sender{
    int tag=[(UIButton *)sender.noOfCommentsButton tag];
    NSLog(@"The tag clicked:%d",tag);  
}

其中Blogcell是我自定义单元格的类。

但是我在NSLog(@"The tag clicked:%d",tag);这一行得到例外,我不确定原因。

2 个答案:

答案 0 :(得分:1)

  
      
  • (IBAction)showComments :( BlogCell *)发件人{
  •   

这是错误的 - sender是按钮,而不是单元格。所以它应该是:

- (IBAction)showComments:(UIButton *)sender {

答案 1 :(得分:0)

如果您将NSLog更改为此

NSLog(@"The tag clicked:%il",(long)tag);

如果日志上有错误。

谢谢,吉姆