2016-04-25 19 views
6

i altyazı etiketli numberoflines = 0Standart UITableView Hücre otomatik yükseklik

sahiptir tarzı uitableviewcellstylesubtitle, bir hücre ile, bir UITableViewController var ve

tableView.rowHeight = UITableViewAutomaticDimension 
tableView.estimatedRowHeight = 44.0 

yaparsanız hücreler otomatik dont yükseklik, gerçekten doğru olabilir - varsayılan stil hücrelerde bunu kullanamazsınız?

DÜZENLEME:

Basit nüfus

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

Daha fazla bilgiye ihtiyacımız var. Lütfen hücreleri nasıl doldurduğunuzu gösterin. Artı, autolayout kullanıyor musunuz? – ozgur

+0

Belirtildiği gibi, altyazı stiline sahip varsayılan bir hücreye sahip olan bir uitableviewcontroller, bu nedenle otomatik ekleme ekleyemezsiniz, – magnuskahr

+0

üzerindeki popülasyonu ekleyecektir. Hücreyi döndürmeden önce 'cell.layoutIfNeeded()' diyebilir misiniz? – ozgur

cevap

4

GÜNCELLEME !!! Varsayılan hücre altyazısının hücreyi otomatik hale getirmesi için, iki etiketin satır sayısını 0 olarak ayarlamanız gerekir. Aksi halde çalışmaz. Tuhaf.

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

yapabilirsiniz oto boyutlandırma varsayılan sytled hücreleri. En basit haliyle aşağıdaki koda sahibim. Varsayılan stillenmiş altyazı hücresini otomatik olarak yeniden boyutlandırma.

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

Aynen yazdığınız gibi aynı şeyi çözdüm, hücre büyür ama hala bazı metinleri keser gibi görüyorum – magnuskahr

+0

Gerçekten de öyle. Sanırım alt sınıflara ihtiyacınız var. Garip olsa da. Aydınlatıcı soru için başvurunuz. – oyalhi