如何解决Swift-如何将单元格项目的数量划分为多个部分?
例如,我的收藏夹视图中有100个或更多(动态)编号商品,并且我想按每个部分将收藏品除以20
第1部分(1-20) 第2节(21-40) 等等...
我已经有了一个带有Collection View的简单水平滚动条的代码,并且工作正常。
let reuseIdentifier = "cell"
var items = ["1","2","3","4",... ] //lets assume its dynamic array
@IBOutlet weak var collectionView: UICollectionView!
var participantsList = [subList]()
override func viewDidLoad() {
super.viewDidLoad()
}
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
return self.items.count
}
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,for: indexPath as IndexPath) as! MyCollectionViewCell
cell.myLabel.text = self.items[indexPath.item]
return cell
}
func collectionView(_ collectionView: UICollectionView,didSelectItemAt indexPath: IndexPath) {
print("You selected cell #\(indexPath.item)!")
let alert = UIAlertController(title: "Participant",message: "\(indexPath.item)",preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Okay",style: UIAlertAction.Style.default,handler: nil))
self.present(alert,animated: true,completion: nil)
}
但是我想发生的事情是这样的
基本上我正在制作的应用是邮票集会。我开始扫描QR码,扫描时该项目变色。现在,我从JSON后端获取数据列表,并将其显示为数组中的项目
邮票的数量应该超过一百,并且可能会随着时间的推移而增加。
所以我需要的是将数组的数量分成每节20个,并显示它们并可以水平滚动
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。