2010-01-21 19 views

回答

15

我不知道你的意思是「正確的」。該indexPath.row始終是本地的部分,這意味着

section 0 
--------- 
[ row 0 ] 
[ row 1 ] 
[ row 2 ] 
---------  
section 1 
--------- 
[ row 0 ] 
[ row 1 ] 
--------- 
section 2 
--------- 
[ row 0 ] 
[ row 1 ] 
[ row 2 ] 
[ row 3 ] 
---------  

要獲得全局行,你可以計算的部分和。

NSUInteger row = 0; 
NSUInteger sect = indexPath.section; 
for (NSUInteger i = 0; i < sect; ++ i) 
    row += [dataSource tableView:tableView numberOfRowsInSection:i]; 
row += indexPath.row; 
return row; 
+0

是的..正確,但例如第2節(第1行)代表全部 第6行,我怎麼能得到它? – 2010-01-21 08:21:12

+0

@senthilmuthu:我明白了。查看更新。 – kennytm 2010-01-21 08:27:09

1

的UITableView發送代表一

willSelectRowAtIndexPath:didSelectRowAtIndexPath:消息

並將它發送一個

UITableViewSelectionDidChangeNotification通知觀察者。

通過收聽這些消息,您將知道選擇了哪些行。

在xCode中有一個帶有UITableView的模板,這是學習UITableView的一個很好的起點。你可以在NSArray的字符串中實現它作爲你的數據源。這樣將您的學習精力集中在UITableView代碼上。

最好的方法是製作一個簡單的UITableView,並且一步一步地調出委託方法以及任何對觀察者的調用。

蘋果類的參考將讓你很長的路。

相關問題