Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 将数据传递到collectionViewCell,如何使其更平滑发现问题_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

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:)
?Show
cellForItemAt
@Larme我在cellForItemAt函数上设置了数据,并在设置它和数据后调用setupData(),我只是模拟它,而不是从api调用。。抱歉,我更新了我的问题。你的代码不应该“慢”那么多。你的数据不大。如果
data.stepIconImage
真的很重,比如在20*20 pts UIImageView中显示的4k*4k px图像,它可能会变慢。。。但我不认为这是问题所在。@Larme我也尝试删除该部分,但仍然滞后。(我的图标仅36*36)@Larme有关详细信息,我的收藏视图位于TableViewCell中,这是问题的原因吗?