简体   繁体   English

构建静态表格视图后,应用程序在模拟器上未显示任何内容

[英]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 . 我正在学习如何从此url( http://manenko.com/2014/12/16/how-to-create-an-input-form-using-uitableview.html )制作static table views它所说的一切以及按照指示进行的操作,我从类内部删除了所有方法,包括numberOfSectionInTableViewnumberOfRowsInSectioncellForRowAtIndexPath 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! 伙计们,谢谢您的回答!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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