2011-09-07 78 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

相关问题