2015-03-02 106 views
-1

我有3個功能:如何在swift中使用多個tableView函數?

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

您是否理解代表或事件的概念? – 2015-03-02 15:41:07

回答

1

沒有這些是UITableViewDataSource/UITableViewDelegate方法,當你實現這個協議你必須指定的方法和表視圖不會沒有它的工作。

相關問題