0

我创建了一个自定义单元格并在其上放置按钮,按钮事件是这样的

   [cell.BtnRequest addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];

和 didtapbutton 代码是这样的

 - (void)didTapButton:(id)sender {

    WorkerDetailsVC *wvc=[self.storyboard instantiateViewControllerWithIdentifier:@"workerdetailsvc"];
    NSIndexPath *indepath = [self.tblorderdata indexPathForCell:sender];

    wvc.arrworkarrequest=[arrData objectAtIndex:indepath.row];

    NSLog(@" arr send :%@", wvc.arrworkarrequest);

    wvc.struserid = struserid;

   [self.navigationController pushViewController:wvc animated:YES];

    }

在下一页我得到了数组 arrworkarrequest 并且在加载所有下一页后它会显示这样的错误

       2014-10-01 15:08:42.607 demo[2151:60b] -[__NSCFNumber length]: unrecognized selector sent to instance 0x911a860
       2014-10-01 15:08:42.613 dmeo[2151:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x911a860'
4

2 回答 2

3

你的问题是它sender的类型UIButton不是 UITableViewCell,所以它卡在了,[self.tblorderdata indexPathForCell:sender]因为该方法调用需要一个UITableViewCell.

您需要找到按钮所在的单元格。您可以使用 while 循环来执行此操作(尽管它有点可怕)。就像是:

id obj = sender;
while (![obj isKindOfClass:[UITableViewCell class]]) {
  obj = [sender superview];
}

[self.tblorderdata indexPathForCell:obj];

这感觉就像它在滥用视图层次结构。

于 2014-10-01T10:09:00.127 回答
-2

如果您直接比较字符串的长度,则会发生这种情况

例如

NSString *myString = @"2";

使用这个语句会产生错误

如果(myString.length==2)

于 2014-10-01T10:14:34.650 回答