UPDATE !!! Damit der Standard-Zellen-Untertitel die Zelle autorisiert, müssen Sie die Anzahl der Zeilen auf label auf 0 setzen. Andernfalls funktioniert es nicht. Seltsam.
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.numberOfLines = 0
Sie können die Standardgröße der Zellen automatisch anpassen. In seiner einfachsten Form habe ich den folgenden Code. Die Größe der Standard-Untertitel-Zelle wird automatisch angepasst.
class ViewController: UIViewController {
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let thisHelpArticle = "Lorem ipsum dolor sit amet, vel porttitor blandit, aliquam tristique vestibulum, enim vel eros fames id, in gravida vestibulum gravida tempor, et vel libero sed mauris. Suspendisse ut placerat viverra dictum, ante ante vel ut vestibulum sollicitudin phasellus. Dictumst adipiscing adipiscing nisl, fusce ut. Ante wisi pellentesque, et aliquam rhoncus eget convallis quam voluptate, ut nec quis, sodales ullamcorper elementum pellentesque sagittis vitae, dolor justo fermentum amet risus. Eu placerat ultricies. Ipsum sodales, massa elit, in neque, sed penatibus gravida, cursus eget. Ut tincidunt at eu, wisi dis vel penatibus eget, volutpat ligula vel tortor morbi feugiat, dui et eiusmod dis sociis. Iaculis lorem molestie laoreet sit, orci commodo, fusce vestibulum sapien, quisque egestas maecenas sed rem in nisl."
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.numberOfLines = 0
cell.textLabel!.text = thisHelpArticle
cell.detailTextLabel!.text = thisHelpArticle
return cell
}
}
extension ViewController: UITableViewDelegate {
}
Wir brauchen mehr Informationen. Bitte zeigen Sie uns, wie Sie Zellen bevölkern. Plus, verwenden Sie automatisches Layout? – ozgur
Wie bereits erwähnt, ist es nur ein uitableviewcontroller mit einer Standardzelle mit dem Untertitel-Stil, so dass Sie kein automatisches Layout hinzufügen können, wird Population über – magnuskahr
hinzufügen Können Sie 'cell.layoutIfNeeded()' direkt vor dem Zurückgeben der Zelle aufrufen? – ozgur