如何解决如何解决 UICollectionViewFlowLayoutBreakForInvalidSizes
我找不到这个问题的答案,也许是因为我的代码不同,我不知道,但最后,我没有找到答案,collectionView 一直抱怨 UICollectionViewFlowLayoutBreakForInvalidSizes 并希望我抓住错误符号断点,但我即使断点调试器也没有显示有关错误的任何信息,这是我实现 collectionView 的方法,如果有人能在我的代码中找到问题,请告诉我
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}; 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,height: estmatedFrame.height + 20)
cell.textBubbleView.frame = CGRect(x: view.frame.width - estmatedFrame.width - 16 - 8 - 16 - 10,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,sizeForItemAt indexPath: IndexPath) -> CGSize {
let messagetext = messages[indexPath.item].text
let size = CGSize(width: 250,attributes: [ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)],context: nil)
return CGSize(width: view.safeAreaLayoutGuide.layoutFrame.width,height: estmatedFrame.height + 20)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。