2011-09-07 76 views
0

我發現了一個示例,我試圖將我的頭包裹起來,我有一個子視圖,它將從我的在線資源的值加載到uitableview單元的部分中。現在我想捕獲單元格選擇並將該數據傳回給選定的父視圖單元格。我認爲這個例子是我需要得到它的工作,但我努力去理解這個例子中的一些變量,希望有人能夠幫助我更好地理解它。如何將單元格選擇加載到父項中uitableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // do usual stuff here including getting the cell 

    // determine the data from the IndexPath.row 

    if (data == self.checkedData) 
    { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // determine the selected data from the IndexPath.row 

    if (data != self.checkedData) { 
     self.checkedData = data; 
    } 

    [tableView reloadData]; 
} 

我的主要問題是與數據self.checkedData是數據中的數據從值陣列回來已解析?什麼是checkedData?基本上我想在選中單元格的末尾有這些複選標記。

回答

1

考慮到這幾行代碼沒有太多上下文,我可能會錯誤,但我會試一試。

首先,它看起來像一次只能檢查一個單元格。

Data似乎是當前的單元格和checkedData一種方式來跟蹤哪個單元格將得到複選標記。

每當一個小區選擇它標誌着:

if (data != self.checkedData) { 
    self.checkedData = data; 
} 

而且控制器詢問TableView重繪(即重裝)本身又:

[tableView reloadData]; 

當該動作被觸發後處理,將代表呼叫tableView:cellForRowAtIndexPath:(以及其他方法),如果您是選定的單元格,則會顯示一個複選標記:

if (data == self.checkedData) 
{ 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 

否則,你不這樣做:

else { 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 
+0

是什麼self.checkedData以及如何創建我自己的一個? –

+0

ahh它的tyep indexpath ** @屬性(nonatomic,retain)NSIndexPath * checkedData; ** –

+0

如果'checkedData'是一個'NSIndexPath',那麼我的回答是正確的。 – rjgonzo

相關問題