Ios UITableView是否具有保存所有单元格的数组属性?

Ios UITableView是否具有保存所有单元格的数组属性?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在我的一个方法中,我希望在我拥有的单元格之间迭代并对其执行更改,例如: for (UITableViewCell *cell in ___________) { cell.accessoryType = accessoryType = UITableViewCellAccessoryCheckmark; } 那么,是否有一个属性将完成这个 tnx 只有可见单元格数组self.tableView.visibleCells for (UITableViewCell *cell in se

在我的一个方法中,我希望在我拥有的单元格之间迭代并对其执行更改,例如:

for (UITableViewCell *cell in ___________) {

    cell.accessoryType = accessoryType = UITableViewCellAccessoryCheckmark;
}
那么,是否有一个属性将完成这个


tnx

只有可见单元格数组
self.tableView.visibleCells

for (UITableViewCell *cell in self.tableView.visibleCells) {

    cell.accessoryType = accessoryType = UITableViewCellAccessoryCheckmark;
}

只有可见单元格数组
self.tableView.visibleCells

for (UITableViewCell *cell in self.tableView.visibleCells) {

    cell.accessoryType = accessoryType = UITableViewCellAccessoryCheckmark;
}

UITableView
本身对其内容了解不多。这就是it的
dataSource
delegate的工作。有关详细信息,请参阅文档

而不是以线性的方式思考问题。将问题视为事件驱动的。如果要在显示单元格之前对其进行修改,可以在
UITableViewDelegate


编辑:如果您希望设置
accesoryType
,您可能应该尝试使用。因为这是您将可重用单元出列或手动
alloc]init]
'1的地方。

UITableView本身对其内容知之甚少。这就是it的
dataSource
delegate的工作。有关详细信息,请参阅文档

而不是以线性的方式思考问题。将问题视为事件驱动的。如果要在显示单元格之前对其进行修改,可以在
UITableViewDelegate


编辑:如果您希望设置
accesoryType
,您可能应该尝试使用。因为这是您将可重用单元出列或手动
alloc]init]
的地方。

您是否尝试过:yourTableView.visibleCells

您是否尝试过:yourTableView.visibleCells

是正确的

但是您应该避免像这样对单元格进行更改。相反,您应该告诉tableView您的单元格已更新,并在
-[id tableView:cellforrowatinexpath:][/code>中提供更改,如下所示:

- (IBAction)toggleSelecting:(id)sender {
    [[self tableView] setEditing:![[self tableView] isEditing] animated:YES];
//  or with custom use with own BOOL property:
//  [self setEditing:![self editing]];
    [[self tableView] reloadRowsAtIndexPaths:[[self tableView] indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationFade];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//  cell setup here...

//  or with custom use with own BOOL property:
//  if ([self editing]) {
    if ([[tableView] isEditing]) {
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }

    return cell;
}
这是对的

但是您应该避免像这样对单元格进行更改。相反,您应该告诉tableView您的单元格已更新,并在
-[id tableView:cellforrowatinexpath:][/code>中提供更改,如下所示:

- (IBAction)toggleSelecting:(id)sender {
    [[self tableView] setEditing:![[self tableView] isEditing] animated:YES];
//  or with custom use with own BOOL property:
//  [self setEditing:![self editing]];
    [[self tableView] reloadRowsAtIndexPaths:[[self tableView] indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationFade];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//  cell setup here...

//  or with custom use with own BOOL property:
//  if ([self editing]) {
    if ([[tableView] isEditing]) {
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }

    return cell;
}

可能无法在一个数组中获取所有单元格。但您可以尝试使用以下方法:

let cellsArray: []

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    //Your data source methods
    let cell = ......
    ....

    cellsArray.append(cell)
}

这样,您可以在加载视图后获得单元格数组。我认为没有其他方法可以做到这一点。

可能无法在一个数组中获取所有单元格。但您可以尝试使用以下方法:

let cellsArray: []

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    //Your data source methods
    let cell = ......
    ....

    cellsArray.append(cell)
}

这样,您可以在加载视图后获得单元格数组。我认为没有其他方法可以做到这一点。

只有在给定时刻可见的细胞存在。对不可见的单元格进行更改将无效。最好对
CellForRowatineXpath:
方法中的AccessoryType进行此更改,然后在发生更改时重新加载表(或节)。遍历数据源。只有在给定时刻可见的单元格才存在。对不可见的单元格进行更改将无效。最好对
cellforrowatinexpath:
方法中的AccessoryType进行此更改,然后在发生更改时重新加载表(或节)。遍历数据源。