如何在swift中拥有多个tableView函数?

时间:2015-03-02 14:34:30

标签: iphone swift

我有3个功能:

 override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return fruits.count
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath ) {
    if indexPath.row == 1 {
        self.performSegueWithIdentifier("Herp", sender: self)
    }

}

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

        let fruit = fruits[indexPath.row] as Fruit
        cell.textLabel?.text = fruit.name
        cell.detailTextLabel?.text = fruit.desc
        return cell
}

有没有办法将它们组合成一个单独的函数,而不是有3个单独的tableView函数?

1 个答案:

答案 0 :(得分:1)

实现此协议时,这些都不是UITableViewDataSource/UITableViewDelegate方法,您必须指定方法,如果没有它,表格视图将不起作用。