Tworzę 2 sekcje UITableView
. Pierwsza sekcja używa UITableViewCells
w stylu Default
, druga używa stylu Subtitle
. Obie komórki mogą mieć wielowierszową etykietę tekstową.UITableViewAutomaticDimension nie działa poprawnie z napisami UITableViewCells
Ustawiłem tabelę na rowHeight
na UITableViewAutomaticDimension
.
Jak widać na poniższym zrzucie ekranu, UITableViewAutomaticDimension
jest przestrzegana tylko częściowo przy użyciu stylu Subtitle
: wysokość wydaje się pasować „wysokość s ale nie detailLabel
zwanej dalej” textLabel
jeden s.
Jak ustawić komórkę Subtitle
w odpowiedniej wysokości?
Niektóre kodu:
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableViewAutomaticDimension
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "defaultCell")
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "subtitleCell")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section === 1 {
var cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "subtitleCell")
cell.textLabel?.numberOfLines = 0
cell.textLabel?.text = "A Long text..."
cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.text = "A Long text..."
return cell
}
else {
var cell = tableView.dequeueReusableCellWithIdentifier("defaultCell") as! UITableViewCell
cell.textLabel!.text = "A long text..."
cell.textLabel?.numberOfLines = 0
return cell
}
}
Próbowałem zaimplementować podklasa UITableViewCell
ale wiele problemów z autoLayout i sekcji tytułów (długa historia), więc zastanawiam się, czy mógłbym Napraw problem w prostszy sposób.
Byłaś kiedykolwiek w stanie rozwiązać ten problem? – Jan