简体   繁体   中英

App doesn't show up anything on simulator after building static Table View

I'm learning how to make static table views from this url ( http://manenko.com/2014/12/16/how-to-create-an-input-form-using-uitableview.html ) I've followed everything it says and also as instructed, I delete all the methods from inside the class including the numberOfSectionInTableView , numberOfRowsInSection , and cellForRowAtIndexPath . The app failed to build. If I reinsert the methods without changing anything, The app works but didn't show anything, just an empty canvas. How do we solve this problem? It's the first time I use storyboard to design my app. Thanks!

here's the full code

import UIKit

class TableViewController: UITableViewController {

@IBOutlet var labels: [UILabel]!


override func viewDidLoad() {
    super.viewDidLoad()

    updateWidthForLabels(labels)


}

func calculateLabelWidth(label: UILabel) -> CGFloat {

    let labelSize = label.sizeThatFits(CGSize(width: CGFloat.max, height: label.frame.height))

    return labelSize.width
}

func calculateMaxLabelWidth(labels: [UILabel]) -> CGFloat {

    return labels.map(calculateLabelWidth).reduce(0, combine: max)
}

func updateWidthForLabels(labels: [UILabel]) {

    let maxLabelWidth = calculateMaxLabelWidth(labels)

    for label in labels {

        let constraint = NSLayoutConstraint(item: label, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: maxLabelWidth)

        label.addConstraint(constraint)
    }
}

Check the delgates for the tableview,It may help you

在此处输入图片说明

Turns out I forgot to uncomment the close curly brackets "}" And it works marvellous. Thank you for your answers, guys!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM