在故事板中编辑 UITableViewController 并在定义 VC class 之后
Edited UITableViewController in storyboard and after defining the VC class
我正在使用 swift 和 XCode 6.3.1。我在带有静态单元格的故事板中编辑了一个 table 视图控制器。想要对标签和插座进行编程,我创建了一个新的 UITableViewController Cocoa Touch File 并定义了视图控制器 class 我刚刚制作的 Cocoa Touch File。然而,一旦我声明了 class,我在情节提要中编辑的任何内容都不会出现在模拟器中。
import UIKit
class TableViewController: UITableViewController {
@IBOutlet weak var distanceSliderLbl: UILabel!
@IBOutlet weak var distanceSlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
@IBAction func distanceSlider_Slide(sender: AnyObject) {
var currentValue = Int(distanceSlider.value)
distanceSliderLbl.text = "\(currentValue)"
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
return cell
}
有什么办法可以解决这个问题吗?
删除创建文件时由 XCode 生成的三个 tableview
函数。
前两个函数决定了您的 table 将有多少节和行。现在你说你的 table 有 0 个部分,所以这正是你得到的 - 什么都没有。由于您有静态单元格,因此不需要这些函数,因为数字是由您在情节提要中固定的。如果您有由代码生成的动态单元格,您可能不知道总共有多少节和单元格,所以您会使用这些函数。
第三个函数将使用单元格标识符来格式化动态生成的单元格,但同样,您不需要它,因为单元格是固定的(静态的)
我正在使用 swift 和 XCode 6.3.1。我在带有静态单元格的故事板中编辑了一个 table 视图控制器。想要对标签和插座进行编程,我创建了一个新的 UITableViewController Cocoa Touch File 并定义了视图控制器 class 我刚刚制作的 Cocoa Touch File。然而,一旦我声明了 class,我在情节提要中编辑的任何内容都不会出现在模拟器中。
import UIKit
class TableViewController: UITableViewController {
@IBOutlet weak var distanceSliderLbl: UILabel!
@IBOutlet weak var distanceSlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
@IBAction func distanceSlider_Slide(sender: AnyObject) {
var currentValue = Int(distanceSlider.value)
distanceSliderLbl.text = "\(currentValue)"
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
return cell
}
有什么办法可以解决这个问题吗?
删除创建文件时由 XCode 生成的三个 tableview
函数。
前两个函数决定了您的 table 将有多少节和行。现在你说你的 table 有 0 个部分,所以这正是你得到的 - 什么都没有。由于您有静态单元格,因此不需要这些函数,因为数字是由您在情节提要中固定的。如果您有由代码生成的动态单元格,您可能不知道总共有多少节和单元格,所以您会使用这些函数。
第三个函数将使用单元格标识符来格式化动态生成的单元格,但同样,您不需要它,因为单元格是固定的(静态的)