[英]App doesn't show up anything on simulator after building static Table View
我正在學習如何從此url( http://manenko.com/2014/12/16/how-to-create-an-input-form-using-uitableview.html )制作static
table views
它所說的一切以及按照指示進行的操作,我從類內部刪除了所有方法,包括numberOfSectionInTableView
, numberOfRowsInSection
和cellForRowAtIndexPath
。 該應用無法生成。 如果我重新插入方法而不進行任何更改,則該應用程序可以運行,但什么也沒顯示,只是一塊空畫布。 我們如何解決這個問題? 這是我第一次使用情節提要來設計我的應用程序。 謝謝!
這是完整的代碼
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)
}
}
原來,我忘了取消對大括號“}”的注釋,它的工作很棒。 伙計們,謝謝您的回答!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.