2015-03-02 2 views
-1

У меня есть 3 функции:Как я могу использовать несколько функций tableView в swift?

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

Вы понимаете концепцию делегатов или событий? –

ответ

1

Нет, это методы UITableViewDataSource/UITableViewDelegate при реализации этого протокола вы должны указать методы, и представление таблицы не будет работать без него.

Смежные вопросы