Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
Ios 自定义表视图多选复选标记_Ios_Tableview - Fatal编程技术网

Ios 自定义表视图多选复选标记

Ios 自定义表视图多选复选标记,ios,tableview,Ios,Tableview,我从中学到了如何启用“表视图”多重选择。但是我如何定制这个呢?如何用自己的视图替换这些默认视图,如下图所示 AUItableViewCell是UIView的子类,因此您可以调用addSubview在每个单元格上添加一个UIImage视图,或者您可以创建自己的UItableViewCell类 希望这有帮助 我找到了自己的解决方案:更改自动布局约束 我的表格视图单元格是一个自定义单元格,在其中我需要将所有视图向右移动以显示选择指示器,因此最初我在自定义视图后面放置了一个自定义指示器,然后在自定义单元

我从中学到了如何启用“表视图”多重选择。但是我如何定制这个呢?如何用自己的视图替换这些默认视图,如下图所示


A
UItableViewCell
UIView
的子类,因此您可以调用
addSubview
在每个单元格上添加一个
UIImage
视图,或者您可以创建自己的UItableViewCell类


希望这有帮助

我找到了自己的解决方案:更改
自动布局约束

我的表格视图单元格是一个自定义单元格,在其中我需要将所有视图向右移动以显示选择指示器,因此最初我在自定义视图后面放置了一个自定义指示器,然后在自定义单元格子类中设置了2个方法来更新视图的约束,以显示下面的指示器

它们看起来像这样:

// in the cell subclass

- (void)showSelectionIndicator {
  self.imageViewLeadingConstraint.constant = 50.f;
}

- (void)hideSelectionIndicator {
  self.imageViewLeadingConstraint.constant = 15.f;
}
// ... normal cell set up
if (self.isSelectingDownloads) {
  [cell showSelectionIndicator];
} else {
  [cell hideSelectionIndicator];
}
// return cell
imageViewLeadingConstraint
只是一个前导约束,用于确定单元格中所有视图的位置

然后,在视图控制器中,我自己管理选择状态和选择的索引。在
cellforrowatinexpath
方法中,我将另外设置单元格,如下所示:

// in the cell subclass

- (void)showSelectionIndicator {
  self.imageViewLeadingConstraint.constant = 50.f;
}

- (void)hideSelectionIndicator {
  self.imageViewLeadingConstraint.constant = 15.f;
}
// ... normal cell set up
if (self.isSelectingDownloads) {
  [cell showSelectionIndicator];
} else {
  [cell hideSelectionIndicator];
}
// return cell
我还有一个切换选择状态的方法:

- (void)toggleDownloading {
  self.isSelectingDownloads = !self.isSelectingDownloads;

  [self.tableView reloadData];
}

这让一切都起作用了。通过调用
toggleDownloading
,单元格中的视图将按预期向右移动。当然,我还需要在
didselectrowatinexpath
中执行一些逻辑来管理选择。

谢谢,但是这些视图(在图像中的红色圆圈中)不受我的控制,它们在表格视图进入编辑模式时出现,无论是系统样式单元格还是自定义单元格。您不需要使用这些视图,您可以创建自己的自定义单元格,并向其中添加任何您喜欢的内容。我明白您的意思。这就是我得到解决方案的原因——使用单元格中的自定义视图,并通过更改自动布局约束来移动它们,表视图不需要进入编辑模式。干杯