How to solve UICollectionViewFlowLayoutBreakForInvalidSizes

时间秒杀一切 提交于 2021-01-29 12:24:17

问题


I couldn't find an answer to this problem maybe because my code is different I don't know but in the end, I didn't found an answer, collectionView keep complaining about UICollectionViewFlowLayoutBreakForInvalidSizes and wants me to catch the err with symbolic breakpoint but I even with the breakpoint debugger not showing any information about the err, here is how I'm implementing collectionView if anyone could find the problem in my code please let me know

The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7f86d50a9b70>, and it is attached to <UICollectionView: 0x7f86d4944000; frame = (0 61; 414 317); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600002e397a0>; layer = <CALayer: 0x60000201b120>; contentOffset: {-5, 1169.5}; contentSize: {404, 1557.1875}; adjustedContentInset: {5, 5, 5, 5}; layout: <UICollectionViewFlowLayout: 0x7f86d50a9b70>; dataSource: <DELEVARE___ÿØŸäŸÑŸäŸÅÿ±Ÿä.DriverChat: 0x7f86d4849c00>>. 2021-01-16 17:57:24.377551+0200 DELEVARE - ديليفري[63548:1297733] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.alwaysBounceVertical = true
        cv.contentInset = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
        cv.backgroundColor = .white
        cv.register(driverMessagesCell.self, forCellWithReuseIdentifier: "driverMessagesCell")
        cv.layoutIfNeeded()
        cv.translatesAutoresizingMaskIntoConstraints = false
        return cv
    }()

override func viewDidLoad() {
        super.viewDidLoad()
        
        collectionView.delegate = self
        collectionView.dataSource = self
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return messages.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "driverMessagesCell", for: indexPath) as! driverMessagesCell
        
        cell.messageTextView.text = messages[indexPath.item].text
        cell.profileImg.image = messages[indexPath.row].image
        
        let messagetext = messages[indexPath.item].text
            let size = CGSize(width: 250, height: 1000)
            let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
            let estmatedFrame = NSString(string: messagetext).boundingRect(with: size, options: options, attributes: [ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18)], context: nil)
            
        let Messages = messages[indexPath.item]
        if Messages.isSender.boolValue == false{
            
        cell.messageTextView.frame = CGRect(x: 48 + 8, y: 0, width: estmatedFrame.width + 16, height: estmatedFrame.height + 20)
        cell.textBubbleView.frame = CGRect(x: 48 - 10, y: -4, width: estmatedFrame.width + 16 + 8 + 16, height: estmatedFrame.height + 20 + 4)
        
        cell.bubbleImg.image = driverMessagesCell.grayBubble
        cell.bubbleImg.tintColor = UIColor(white: 0.95, alpha: 1)
        cell.messageTextView.textColor = .darkGray
        
        cell.profileImg.isHidden = false
            cell.url = orderData?.userImg
            
        } else {
            
            cell.messageTextView.frame = CGRect(x: view.frame.width - estmatedFrame.width - 16 - 16 - 8, y: 0, width: estmatedFrame.width + 16, height: estmatedFrame.height + 20)
            cell.textBubbleView.frame = CGRect(x: view.frame.width - estmatedFrame.width - 16 - 8 - 16 - 10, y: -4, width: estmatedFrame.width + 16 + 8 + 10, height: estmatedFrame.height + 20 + 6)
            cell.bubbleImg.image = driverMessagesCell.redBubble
            cell.bubbleImg.tintColor = UIColor.delevareColor.withAlphaComponent(0.95)
            cell.messageTextView.textColor = .white
            cell.profileImg.isHidden = true
        }
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0)
    }
    
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        
        let messagetext = messages[indexPath.item].text
            let size = CGSize(width: 250, height: 1000)
            let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
            let estmatedFrame = NSString(string: messagetext).boundingRect(with: size, options: options, attributes: [ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)], context: nil)
            
        return CGSize(width: view.safeAreaLayoutGuide.layoutFrame.width, height: estmatedFrame.height + 20)
        

    }

来源:https://stackoverflow.com/questions/65751634/how-to-solve-uicollectionviewflowlayoutbreakforinvalidsizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!