Swift 将数据传递到collectionViewCell,如何使其更平滑发现问题
根据我的问题,我必须将数据传递到我的集合视图单元格 当滚动时,它使拉吉。这是因为我的设置数据功能,它传递了太大的数据,但我不知道如何修复它 我的手机课Swift 将数据传递到collectionViewCell,如何使其更平滑发现问题,swift,uicollectionview,uicollectionviewcell,Swift,Uicollectionview,Uicollectionviewcell,根据我的问题,我必须将数据传递到我的集合视图单元格 当滚动时,它使拉吉。这是因为我的设置数据功能,它传递了太大的数据,但我不知道如何修复它 我的手机课 class VerificationStepCollectionViewCell: UICollectionViewCell { @IBOutlet weak var stepLabel: UILabel! @IBOutlet weak var stepTitleLabel: UILabel! @IBOutlet weak
class VerificationStepCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var stepLabel: UILabel!
@IBOutlet weak var stepTitleLabel: UILabel!
@IBOutlet weak var stepNoLabel: UILabel!
@IBOutlet weak var iconImageView: UIImageView!
@IBOutlet weak var stepDescriptionLabel: UILabel!
@IBOutlet weak var stepStatusLabel: UILabel!
@IBOutlet weak var stepStatusView: UIView!
@IBOutlet weak var buttonStatus: BaseButton!
var currentStepType: VerifyAccountStepType?
var currentStatus: UserLevelInfoStatus?
var data: HomeModels.ViewModel.VerifyAccountStepModel? = nil
override func awakeFromNib() {
super.awakeFromNib()
self.setupView()
}
private func setupView() {
self.stepStatusView.layer.cornerRadius = self.stepStatusView.frame.height / 2
}
func setupData() {
guard let data = self.data else { return }
self.currentStepType = data.stepType
self.currentStatus = data.stepStatus
self.stepStatusView.isHidden = data.stepStatus == .notVerify
self.stepLabel.text = "Step\(data.stepNo)"
self.stepTitleLabel.text = data.stepTitle
self.stepNoLabel.text = "\(data.stepNo)"
self.iconImageView.image = data.stepIconImage
self.stepDescriptionLabel.text = data.stepDescription
self.stepStatusLabel.text = "home_unverified_account_\(data.stepStatus.rawValue)_status".localized()
switch data.stepStatus {
case .approve:
self.buttonStatus.setIsEnable(false)
self.buttonStatus.setTitle(data.stepButtonTitle, for: .normal)
self.stepStatusView.backgroundColor = UIColor.Yellows.brighterYellow
self.stepStatusLabel.textColor = .black
case .notVerify:
self.buttonStatus.setIsEnable(true)
self.buttonStatus.setTitle(data.stepButtonTitle, for: .normal)
self.stepStatusLabel.textColor = .white
case .reject:
self.buttonStatus.setIsEnable(true)
self.buttonStatus.setTitle("แก้ไข", for: .normal)
self.stepStatusView.backgroundColor = UIColor.Reds.loss
self.stepStatusLabel.textColor = .white
case .pending:
self.buttonStatus.setIsEnable(false)
self.buttonStatus.setTitle(data.stepButtonTitle, for: .normal)
self.stepStatusView.backgroundColor = UIColor.Oranges.deepOrange
self.stepStatusLabel.textColor = .white
}
}
}
我知道我的数据太大了,但它不得不这么做,有人曾经遇到过这个问题吗?
多谢各位
更新解决方案
它已经发现了我的问题,这是由我的本地化文本函数引起的。
我把它取下来后,一切都很好~ 何时调用
setupData()
?如何传递数据?图像是否多于stepIconImage
?是从网络上发的吗?它是否未加载数据(contentsOf:)
?ShowcellForItemAt
@Larme我在cellForItemAt函数上设置了数据,并在设置它和数据后调用setupData(),我只是模拟它,而不是从api调用。。抱歉,我更新了我的问题。你的代码不应该“慢”那么多。你的数据不大。如果data.stepIconImage
真的很重,比如在20*20 pts UIImageView中显示的4k*4k px图像,它可能会变慢。。。但我不认为这是问题所在。@Larme我也尝试删除该部分,但仍然滞后。(我的图标仅36*36)@Larme有关详细信息,我的收藏视图位于TableViewCell中,这是问题的原因吗?