选择器 (collectionView 单选、多选)(tableView 单选、多选)
在项目工程中用的最多的就是列表了,而且在列表中总会有各种各样的处理。今天和大家分享一下单选和多选的优雅实现。
在tableview单选中:
关于选择有两个基本的方法。
第一种实现
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
其中第一个是点击选择的方法,第二个是取消的方法。
在单选的实现过程中我们可以配置model的选中结果来实现
- (void)configCellStatus:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath Status:(BOOL)status{
CustomTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
SelectModel *model = cell.selectModel;
model.isSelected = status;
cell.selectModel = model;
}
分别在两个选择方法中调用实现。在didSelectRowAtIndexPath中传入状态为YES,在didDeselectRowAtIndexPa