swift - 在prepareForSegue中快速使用tableView

标签 swift controller segue

我在第二个 Controller 中的 tableView 遇到一些问题

第一个 Controller 的代码:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "DetailSegue" {
        let detailViewController = segue.destinationViewController as DetailViewController
        let indexPath = self.liveMatch!.indexPathForSelectedRow()!
    }
}

第二个 Controller 的代码:(DetailViewController)

import UIKit

class DetailViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // Return the number of rows in the section.
        return 5
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("playersCell", forIndexPath: indexPath) as PlayersTableViewCell

        cell.playerName.text = "test"

        return cell
    }
}

以秒为单位的 Controller 表为空;(我该如何修复这个问题?谢谢!

最佳答案

我认为您需要遵守UITableViewDataSource协议(protocol),并实现numberOfSectionsInTableView方法。

因此添加协议(protocol):
类 DetailViewController: UIViewController, UITableViewDataSource {

以及方法

func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
    return 1
}

关于swift - 在prepareForSegue中快速使用tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29140987/

相关文章:

ios - 使用选项卡 View Controller 的 Xcode IOS 转换 View

ios - PFQuery 返回空数组

php - Controller 缺少参数 2 :update() - Laravel

swift - 使用 CATransition 自定义 Segue

ios - 从 swift 应用程序的 OAuth 后台登录

ios - 在使用 FIRDatabase 之前必须调用 FIRApp.configure()。错误,即使我已经调用了它

c++ - VB.NET:未知的 KeyDown 事件问题

ruby-on-rails - 在 Ruby On Rails Controller 方法中使用事务

ios - Swift ios viewDidLoad 或 viewDidAppear

ios - 将图像从 Collection View Controller 快速传递到另一个 View Controller