【发布时间】:2018-11-05 17:14:54
【问题描述】:
我希望能够在我的收藏视图上下滚动时预加载项目。
我正在使用两个数组的数据来加载集合视图中的数据:
(1)availableLabelNames: [String]
(2)availableImageNames: [String]
AvailableImages 中的集合视图函数:
class availableImages: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource
{
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var collectionView: UICollectionView!
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return availableLabelNames.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCollectionViewCell
cell.borderFolder.layer.borderColor = UIColor.black.cgColor
cell.borderFolder.layer.borderWidth = 2
cell.borderFolder.layer.cornerRadius = 5
cell.squareDesign.layer.cornerRadius = 5
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(availableImages.connected(_:)))
cell.imageCell.isUserInteractionEnabled = true
cell.imageCell.tag = indexPath.row
cell.imageCell.addGestureRecognizer(tapGestureRecognizer)
//setting image
cell.imageCell.image = UIImage(named: availableImageNames[indexPath.row])
//setting label
cell.labelName.text = availableLabelNames[indexPath.row]
return cell
}
}
自定义集合视图类:
import UIKit
protocol Normal: class
{
func delete (cell: CustomCollectionViewCell)
func pressed (cell: CustomCollectionViewCell)
func textChanged (cell: CustomCollectionViewCell)
func finishedEditing (cell: CustomCollectionViewCell)
func textStartedEditing (cell: CustomCollectionViewCell)
}
class CustomCollectionViewCell: UICollectionViewCell
{
@IBOutlet weak var imageCell: UIImageView!
@IBOutlet weak var deleteButton: UIButton!
@IBOutlet weak var cellButton: UIButton!
@IBOutlet weak var labelName: UILabel!
@IBOutlet weak var textFieldName: UITextField!
@IBOutlet weak var squareDesign: UIView!
@IBOutlet weak var borderFolder: UIView!
weak var delegate: Normal?
//...class goes on but not important
请有人帮助我,我到处寻找,但就我的申请而言,似乎没有任何效果或有意义。 太感谢了! :)
【问题讨论】:
标签: ios swift uicollectionview collectionview preloading