ios 我无法正确查看tableviewCell中的内容

brc7rcf0  于 2023-01-22  发布在  iOS
关注(0)|答案(1)|浏览(101)

我有一个自定义的tableViewCell,里面有emailText,image和commentText。问题是当我将约束设置为“重置为建议的约束”时,它会像默认单元格一样显示图像,非常窄,像行高30或40。我只能看到图像的一小部分,我甚至不能看到电子邮件和评论。如果我给予我自己的约束,那么我只能看到电子邮件和评论,从来没有看到任何的图像。我该如何解决这个问题?这是我下面的代码,我将尝试显示我得到的结果在图片和图片中的约束,因为我设置他们在情节串连图板。
第一节第一节第一节第一节第二节第一节第三节第一节

import UIKit
import Firebase
import FirebaseFirestore
import SDWebImage

class FeedsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!
    

    var postArray = [POST]()
    //    var emailArray = [String]()
//    var commentArray = [String]()
//    var imageArray = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        fetchFirebaseData()
    }
    
    func fetchFirebaseData() {
        
        let firestoreDatabase = Firestore.firestore()
        firestoreDatabase.collection("POST").order(by: "Date", descending: true).addSnapshotListener { snapshot, error in
            if error != nil {
                print(error?.localizedDescription)
            } else {
                if snapshot?.isEmpty != true && snapshot != nil {
                    
//                    self.emailArray.removeAll(keepingCapacity: false)
//                    self.commentArray.removeAll(keepingCapacity: false)
//                    self.imageArray.removeAll(keepingCapacity: false)
                    self.postArray.removeAll()
                    
                    for document in snapshot!.documents {
                        if let imageURL = document.get("imageUrl") as? String {
                            
                            if let comment = document.get("comment") as? String {
                                                        
                                if let email = document.get("email") as? String {
                                    let post = POST(email: email, comment: comment, image: imageURL)
                                    self.postArray.append(post)
                                                       }
                                                    }
                                                }
                                        }
                    
                    self.tableView.reloadData()
                }
                
            }
        }
        
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return postArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedCell
        cell.emailText.text = postArray[indexPath.row].email
        cell.commentText.text = postArray[indexPath.row].comment
        cell.postImageView.sd_setImage(with: URL(string: self.postArray[indexPath.row].image))
        return cell
    }
}
qpgpyjmq

qpgpyjmq1#

编辑:在我认为我解决了问题之后,我在控制台中得到这些错误

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001d68780 UIImageView:0x143606760.height == 207   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2023-01-21 12:56:19.477442+0300 PhotoShareApp[26983:294545] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600001d2d6d0 UIImageView:0x146008eb0.height == 207   (active)>",
    "<NSLayoutConstraint:0x600001d2db30 UILabel:0x1460090d0.height == 37   (active)>",
    "<NSLayoutConstraint:0x600001d2e2b0 UILabel:0x146009650.height == 48   (active)>",
    "<NSLayoutConstraint:0x600001d2dfe0 V:|-(0)-[UILabel:0x146009650]   (active, names: '|':UITableViewCellContentView:0x146008cd0 )>",
    "<NSLayoutConstraint:0x600001d2e0d0 V:[UILabel:0x146009650]-(NSSpace(8))-[UIImageView:0x146008eb0]   (active)>",
    "<NSLayoutConstraint:0x600001d2def0 V:[UIImageView:0x146008eb0]-(NSSpace(8))-[UILabel:0x1460090d0]   (active)>",
    "<NSLayoutConstraint:0x600001d2e1c0 UITableViewCellContentView:0x146008cd0.bottomMargin == UILabel:0x1460090d0.bottom + 27   (active)>",
    "<NSLayoutConstraint:0x600001d2e030 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x60000070c1c0'UIViewLayoutMarginsGuide']-(11)-|   (active, names: '|':UITableViewCellContentView:0x146008cd0 )>",
    "<NSLayoutConstraint:0x600001d2d270 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x146008cd0.height == 346.333   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001d2d6d0 UIImageView:0x146008eb0.height == 207   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

好的!我通过在imageview中添加一个高度和前后限制来解决我的问题,最后得到了x1c 0d1x

相关问题