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