我一直有對齊問題。消息標籤一直在寫時間戳和用戶名正在消失。我已經嘗試了建議的約束條件,但沒有任何工作適合我。TableView Cell中的對齊
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
//Transform Data From^to load at the bottom
tableView.transform = CGAffineTransform (scaleX: 1,y: -1);
cell?.contentView.transform = CGAffineTransform (scaleX: 1,y: -1);
cell?.accessoryView?.transform = CGAffineTransform (scaleX: 1,y: -1);
//Set username label to display username
let usernameLabel = cell?.viewWithTag(1) as! UILabel
usernameLabel.text = generalRoomDataArr[indexPath.row].username
//Set message label to display message
let messageLabel = cell?.viewWithTag(2) as! UILabel
messageLabel.text = generalRoomDataArr[indexPath.row].message
messageLabel.numberOfLines = 0
//initialize UI Profile Image
let imageView = cell?.viewWithTag(3) as! UIImageView
//Make Porfile Image Cirlce
imageView.layer.cornerRadius = imageView.frame.size.width/2
imageView.clipsToBounds = true
//Set timeStampLabel to current time AGO
let timeStampLabel = cell?.viewWithTag(4) as! UILabel
timeStampLabel.text = generalRoomDataArr[indexPath.row].timeStamp
timeStampLabel.numberOfLines = 0
//Loading and change of Usesrs profile image on chat cell
let userProfileChatImage = generalRoomDataArr[indexPath.row].photoURL
//Load profile image(on cell) with URL & Alamofire Library
let downloadURL = NSURL(string: userProfileChatImage!)
imageView.af_setImage(withURL: downloadURL as! URL)
// your cell coding
return cell!
}
//TableView Cell word wrap (Dynamic Text)
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.estimatedRowHeight = 78
self.tableView.rowHeight = UITableViewAutomaticDimension
我是否需要時間戳標籤設置爲0呢?
messageLabel.numberOfLines = 0
看起來像您的表格單元格未調整其高度以適應具有更多文本的標籤。在提供的圖片中,它們都與我的尺寸相同。 爲了真正瞭解問題所在,請發佈剩餘的tableview代碼以及您設置的約束條件。 – BJHStudios
閱讀此可能會有所幫助。 http://www.appcoda.com/self-sizing-cells/ –
我讀過那篇文章,一切都很好,直到我添加了時間戳。我需要什麼限制才能避免messageLabel重疊和空間? – codechicksrock