2016-04-25 17 views
6

mam UITableViewController, o komórce uitableviewcellstylesubtitle stylu, gdzie podtytuł-label ma numberoflines = 0domyślny UITableView komórki automatyczna wysokość

i jeśli mam zrobić

tableView.rowHeight = UITableViewAutomaticDimension 
tableView.estimatedRowHeight = 44.0 

komórki dont automatyczne wysokość, czy to naprawdę prawda - że nie można jej użyć w domyślnych komórkach w stylu?

EDIT:

Proste populacja

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 
    let thisHelpArticle = helpObjects[indexPath.section] 

    cell.textLabel!.text = thisHelpArticle.helpHeadline 
    cell.detailTextLabel!.text = thisHelpArticle.helpDescription 

    return cell 
} 
+0

Potrzebujemy więcej informacji. Pokaż, jak wypełniasz komórki. Plus, czy korzystasz z autolayout? – ozgur

+0

Jak już wspomniano, jest to tylko kontroler uytecznyview z domyślną komórką ze stylem Subtitle, więc nie można dodać autolayout, doda populację powyżej – magnuskahr

+0

Czy można wywołać 'cell.layoutIfNeeded()' przed zwróceniem komórki? – ozgur

Odpowiedz

4

UPDATE !!! Aby domyślny podtytuł komórki mógł automatycznie zsynchronizować komórkę, MUSISZ ustawić liczbę linii na obu etykietach na 0. W przeciwnym razie nie działa. Dziwne.

cell.textLabel?.numberOfLines = 0 
cell.detailTextLabel?.numberOfLines = 0 

Możesz automatycznie zmienić rozmiar domyślnych komórek sytled. W najprostszej postaci mam następujący kod. Automatycznie zmienia rozmiar domyślnej stylowej komórki napisów.

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 { 

} 
+0

Zorientowałem się tak samo, jak to napisałeś, komórka staje się większa, ale nadal kawałki tekstu, jak widzę – magnuskahr

+0

Rzeczywiście tak. Chyba musisz ją podklasować. Dziwne jednak. Awansuj na pytanie oświetlające. – oyalhi

Powiązane problemy