Problem
, , "Swift TableViewCell xib ". , , :
, , xib, xib, .
, :
- , TableViewCell
- / Storyboard xib
№1 , xib, . .
№2 , . , , , . / Storyboard xib, . , / .
-
, . . . View . 1- 2- MyCell. 3- 4- MyCopyPasteCell. 5- 6- MyPrototypeCell.
MyCell xib , . , . MyCopyPasteCell / Storyboard xib. MyPrototypeCell - , . , xib. xib .

, , ContentView. ( , height=20, aspect=1:1 height=75, .) , . .
// bottomMargin = Profile Image View.bottom + 188.5
bottomMargin = Profile Image.bottom + 17
Profile Image View.top = Username Label.top
Profile Image View.leading = leadingMargin + 2
Profile Image View.top = topMargin + 20
Username Label.leading = Content Text View.leading
// Username Label.top = topMargin + 20
Username Label.trailing = Content Text View.trailing
Username Label.leading = Profile Image View.trailing + 15
trailingMargin = Username Label.trailing + 10
Content Text View.top = Username Label.bottom + 5
Content Text View.leading = leadingMargin + 92
bottomMargin = Content Text View.bottom + 20
// bottomMargin = Profile Image View.bottom + 188.5 , 188.5. Prototype ( ). bottomMargin = Profile Image.bottom + 17, 188.5 17.
// Username Label.top = topMargin + 20 ( topMargin 20) . Profile Image.top = topMargin + 20 ( topMargin 20) Profile Image View.top = Username Label.top ( , .. 20).
MyTableViewController
. / . MyCell MyCopyPasteTableViewCell xib viewDidLoad(). MyPrototypeCell viewDidLoad().
import UIKit
class MyTableViewController: UITableViewController {
let myCell = "MyCell"
let myCopyPasteCell = "MyCopyPasteTableViewCell"
let myPrototypeCell = "MyPrototypeCell"
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: myCell, bundle: nil), forCellReuseIdentifier: myCell)
tableView.register(UINib(nibName: myCopyPasteCell, bundle: nil), forCellReuseIdentifier: myCopyPasteCell)
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: myCell, for: indexPath)
return cell
} else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: myCopyPasteCell, for: indexPath)
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: myPrototypeCell, for: indexPath)
return cell
}
}
}
Github
https://github.com/starkindustries/TableViewCellConstraintsTest