gpt4 book ai didi

swift - 如何在 swift 中向 uicollectionview 添加复选框

转载 作者:行者123 更新时间:2023-11-30 10:14:29 27 4
gpt4 key购买 nike

不久前已经有人问过这个问题并给出了一些答案,但我并没有真正理解其中的任何一个。所以我想知道是否有人可以编写一个易于理解的教程,介绍如何执行下图所示的操作:

http://i.imgur.com/BzIBOkH.jpg?1

如果有人能准确分享如何做到这一点,我将非常感激,因为它看起来真的很酷,我很乐意在我的应用程序中使用类似的东西

最佳答案

Here是可用于复选框单元的示例项目。 (目标 - c)

MyCell.m

// A setter method for checked property
- (void)setChecked:(BOOL)checked {
// Save property value
_checked = checked;

// Update checkbox image
if(checked) {
self.checkBoxImageView.image = [UIImage imageNamed:@"Checked"];
} else {
self.checkBoxImageView.image = [UIImage imageNamed:@"Unchecked"];
}
}

您的收藏 View 单元格

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// Deselect cell first
[collectionView deselectItemAtIndexPath:indexPath animated:YES];

// Get selected cell
MYCell* cell = (MYCell*) [collectionView cellForItemAtIndexPath:indexPath];

// Check if set contains selected cell indexPath
if([self.checkedIndexPaths member:indexPath])
{
// User tapped on checked cell
// Remove selected indexPath from set
[self.checkedIndexPaths removeObject:indexPath];

// Uncheck checkbox on cell
cell.checked = NO;
}
else // User tapped on unchecked cell
{
// Add selected indexPath to set
[self.checkedIndexPaths addObject:indexPath];

// Check checkbox on cell
cell.checked = YES;
}
}

关于swift - 如何在 swift 中向 uicollectionview 添加复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30977144/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com