我的故事板UIImage视图和标签有一些严重的问题 . 我想要的就是让我的约束力得以解决,看看我在故事板中如何设置它 .
UI looks like this
Story Board
我想要的只是我的UI,看看我在故事板中的确切方式 .
Problem 1: 单元格未显示完整长度 .
Problem 2: 我不知道如何设置messageLabel的约束,使其适用于自动动态单元 . 代码是正确的,因为我可以让它工作但我的所有约束都搞砸了,我不知道如何正确设置它们 .
- 我是swift的新手
Code(took out non-relevant functions)
import UIKit
import Foundation
struct postStruct {
let username : String!
let message : String!
let photoURL : String!
}
class GeneralChatroom: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
@IBOutlet weak var messageTextField: UITextField!
@IBOutlet weak var tableView: UITableView!
var generalRoomDataArr = [postStruct]()
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
let ref = FIRDatabase.database().reference()
//let userID = FIRAuth.auth()?.currentUser?.uid
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return generalRoomDataArr.count // your number of cell here
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
//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
//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!
}