簡體   English   中英

我無法正確看到 tableviewCell 中的內容

[英]I cannot see the content inside the tableviewCell properly

我有一個自定義的 tableViewCell,在其中我有一個 emailText、圖像和 commentText。 問題是,當我將約束設置為“重置為建議的約束”時,它會像默認單元格一樣顯示圖像,非常窄,如行高 30 或 40。我只能看到圖像的一小部分,我什至看不到email 並發表評論。 如果我給出自己的約束,那么我只能看到 email 和評論,而永遠看不到任何圖像。 我該如何解決這個問題? 這是我下面的代碼,我將嘗試在圖片中展示我得到的結果和圖片中的約束,因為我在 storyboard 中設置了它們。

模擬器視圖 約束警告 約束條件 故事板的約束

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
    }
}

編輯:在我認為我解決了問題之后,我在控制台中收到了這些錯誤

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 添加高度和前導尾隨約束解決了我的問題,最后這就是我得到的最后結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM