uitableview - 在 Storyboard中和定义 VC 类之后编辑 UITableViewController

标签 uitableview swift xcode6 storyboard tableview

我正在使用 swift 和 XCode 6.3.1。我在 Storyboard中使用静态单元编辑了 TableView Controller 。为了对标签和 socket 进行编程,我创建了一个新的 UITableViewController Cocoa Touch 文件,并定义了我刚刚创建的 Cocoa Touch 文件的 View Controller 类。然而,一旦我声明了该类,我在 Storyboard中编辑的任何内容都不会出现在模拟器中。

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 函数。

前两个函数决定表格将有多少个部分和行。现在你说你的表有 0 个部分,所以这正是你得到的 - 什么也没有。由于您有静态单元格,因此您不需要这些函数,因为该数字是您在 Storyboard中固定的。如果您有由代码生成的动态单元格,您可能不知道总共有多少个部分和单元格,因此您需要使用这些函数。

第三个函数将使用单元格标识符来格式化动态生成的单元格,但同样,您不需要它,因为单元格是固定的(静态)

关于uitableview - 在 Storyboard中和定义 VC 类之后编辑 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30677993/

相关文章:

Swift 标准库工具错误

casting - 如何将 Array<AnyObject> 转换为空数组变量?

swift - 如何使用 Alamofire 1.3 连接到自签名服务器

objective-c - Xcode 符号导航器不显示应用程序符号

swift - Swift 中的 MKMapRectMake 在编译时导致链接器错误

ios - 为什么在交互和滚动时 UITableView 会发生内存泄漏?

ios - 自定义动态 TableViewCell 文本定位

ios - 关闭作为 UITableViewCell 子类的属性以更新值 : Is it a bad idea?

ios - xcode 6 Mac 10.9 中的 Protocol Buffer

ios - iPad 上 UITableView 的背景图片