2010-10-11 51 views
0

我是新來的iphone開發.. 我正在製作一個應用程序,其中表格視圖列出國家的名稱...用戶必須一次選擇一個或多個國家..我想顯示覆選標記泄露按鈕在這是selected..how條目我可以做..允許某些單元格被選中的表格。

和另一thing..i要取消選擇的條目時,用戶在同一name..means的複選標記將被刪除再次點擊..

回答

0

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: 
      (NSIndexPath *)indexPath { 
      // You have an array of countries and track all indexes that are selected. 
      // If the indexing is synced with the cell index, then 
      UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath]; 
      if (/* this index's country is selected */) 
       cell.accessoryType = UITableViewCellAccessoryNone; 
      else { 
       // update this index's country to selected state. 
       cell.accessoryType = UITableViewCellAccessoryCheckmark; 
      // you can keep an array of indexes, which cells/country is selected and store the status of selection in the array for further use. 
      } 
     } 
+0

它解決了我的問題,但現在的問題是。就像在第一個屏幕上我已經選擇了3個條目,當我滾動通過較低的條目(在下一個屏幕)它顯示三個條目預先選擇,但實際上這些都沒有被選中......我怎麼能糾正這個問題..我有一個列表到200個國家.. – 2010-10-11 11:16:36

+0

這是因爲細胞被重新使用。對於解決方案,我可以編輯我的答案。 – karim 2010-10-11 12:32:12

1

要顯示的勾號:

 
cell.accessoryType = UITableViewCellAccessoryCheckmark 

要清除複選標記:

 
cell.accessoryType = UITableViewCellAccessoryNone 

您可以通過測試當前值輕鬆切換。

的方法
相關問題