Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将传感器选择加载到父uitableview中_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone 如何将传感器选择加载到父uitableview中

Iphone 如何将传感器选择加载到父uitableview中,iphone,ios,uitableview,Iphone,Ios,Uitableview,我已经找到了一个我正在努力思考的例子,我有一个子视图,它正在将在线资源中的值加载到uitableview单元格的部分中。。一切正常,但现在我想捕获单元格选择并将数据传递回选定的父视图单元格。我认为这个例子是我需要让它工作的,但是我很难理解这个例子中的一些变量是什么,我希望有人能帮助我更好地理解它 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat

我已经找到了一个我正在努力思考的例子,我有一个子视图,它正在将在线资源中的值加载到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?基本上,我希望在选中时在单元格的末尾打上这些复选标记。

考虑到这几行代码没有太多上下文,我可能错了,但我会尝试一下

首先,看起来一次只能检查一个单元格

Data
似乎是当前单元格,
checkedData
是跟踪哪个单元格将获得选中标记的一种方法

无论何时选择单元格,都会将其标记为:

if (data != self.checkedData) {
   self.checkedData = data;
}
控制器要求
TableView
重新绘制(即重新加载)自身:

[tableView reloadData];
启动该操作后,代理将调用
tableView:cellforrowatinexpath:
(以及其他方法),如果您是所选单元格,则会得到一个复选标记:

if (data == self.checkedData)
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
} 
否则,您不会:

else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}

什么是self.checkedData?我如何创建自己的一个?啊,它是tyep indexpath@property(nonatomic,retain)NSIndexPath*checkedData;如果
checkedData
是一个
nsindepath
,那么我的答案是正确的。我认为
data
indepath
是一样的。虽然我会更改
数据==checkedData
[数据相等:checkedData]