Проблема такова, у меня размер строки определяется автоматически, в зависимости от экрана. Проблема заключается в том что когда func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "chat") as! ChatsTableViewCell;
cell.imageUser.image = UIImage.convertBase64ToImage(imageString: (data?.list[indexPath.row].imageUser)!)
cell.imageUser.layer.cornerRadius = cell.frame.size.height / 2;
cell.imageChat.clipsToBounds = true;
return cell;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "chat") as! ChatsTableViewCell;
cell.imageUser.image = UIImage.convertBase64ToImage(imageString: (data?.list[indexPath.row].imageUser)!)
cell.imageUser.layer.cornerRadius = cell.frame.size.height / 2;
cell.imageUser.clipsToBounds = true;
return cell;
}awakeFromNib)printf. Посмотрите, сколько раз вызывается эта функция и сравните с тем, сколько раз будет вызываться ваш код в tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
import UIKit
final class Cell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
imageView?.clipsToBounds = true
imageView?.contentMode = .scaleAspectFit
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override var frame: CGRect {
didSet {
guard frame.height != oldValue.height else { return }
imageView?.layer.cornerRadius = frame.height / 2.0
print(#function)
}
}
}
final class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(Cell.self, forCellReuseIdentifier: "Cell")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 21;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.imageView?.image = UIImage(named: "c-1-8")!
cell.textLabel?.text = "Ooops";
return cell;
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.frame.width * 0.25;
}
}