我在第二个 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/