Я думаю, что это лучший способ привязать модель к ячейке tableView.Вот что мы обычно делаем:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
cell.textLabel!.text = "foo"
return cell
}
Некоторые другие могут сделать это:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
NSLog("get cell")
let cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
cell.data = data //model passed to cell
}
, которая data
является моделью, а cell.textLabel!.text
будет установлена внутри ячейки (как вawakeFromNib
).
или, может быть, кто-то еще достигнет этого по-другому.Итак, мой вопрос в том, каковы плюсы и минусы каждого способа, и какой из них является наилучшим для паттерна MVC?