indexPath.row中的tableView didSelectRowAtIndexPath方法返回null返回null:indexPathindexPath.row中的tableView didSelectRowAtIndexPath方法
我认为这是应该返回选择的行。
,当我在它(corectly)返回调试器看indexPath: “2个索引[0,0]”
我缺少的东西?
indexPath.row中的tableView didSelectRowAtIndexPath方法返回null返回null:indexPathindexPath.row中的tableView didSelectRowAtIndexPath方法
我认为这是应该返回选择的行。
,当我在它(corectly)返回调试器看indexPath: “2个索引[0,0]”
我缺少的东西?
嗯null
是0
。 row
属性是int
类型 - 也许你错误地将它用作对象或指针。
你提到你想要选择的实际“行”。如果你的意思是你想要的细胞选择的是,这里的如何:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
需要注意的是,如果你以某种方式编程方式选择一排,这不是当前可见,这将返回nil
。
它将PATH返回到所选行,而不是行(或单元格)本身。
indexPath(0,0)是第一部分的第一个单元格。根据你正在运行的测试,这可能是正确的结果。
indexPath.section
告诉你它要求的部分。
indexPath.row
告诉你它想要的那一段中的哪一行。
无论从0开始。
你想要做这样的事情:
if (indexPath.section == 0) { // 1st section
if (indexPath.row == 0) return cell1;
if (indexPath.row == 1) return cell2;
if (indexPath.row == 2) return cell3;
} else if (indexPath.section == 1) { // 2nd section
if (indexPath.row == 0) return cell4;
if (indexPath.row == 1) return cell5;
if (indexPath.row == 2) return cell6;
}
return nil;
我用错了数组访问方法:-S – mjmdavis 2009-07-24 15:39:44