Предполагая, что три различных типа клеток:
class NormalTableViewCell: UITableViewCell:
Это используется для «обычных» клеток вашего внешнего (основного) представления таблицы.
class TableContainingTableviewCell : UITableViewCell
: Это используется для «специальных» ячеек вашего внешних (основного) вида таблицы, которые содержат внутренний вид таблицы (внутри).
class InnerTableViewCell : UITableViewCell
: Используется для ячеек ваших внутренних табличных представлений (содержащихся в ячейках класса TableContainingTableviewCell
).
(Заменить каждый вашими реальными именами классов).
, вы можете использовать этот код:
override func viewDidLoad()
{
super.viewDidLoad()
// This can also be done in storyboard with prototype cells:
self.tableView.registerClass(NormalTableViewCell.class, forCellReuseIdentifier: normalCellIdentifier)
self.tableView.registerClass(TableContainingTableViewCell.class, forCellReuseIdentifier: specialCellIdentifier)
}
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath
) -> UITableViewCell
{
if tableView == self.tableView {
// [A] OUTER TABLE VIEW
if indexPath == index path of table-containing cell {
// (A.1) TABLE-CONTAINING CELL
let cell = tableView.dequeueReusableCellWithIdentifier(specialCellIdentifier, forIndexPath: indexPath) as! TableContainingTableViewCell
// (...configure cell...)
// Setup and refresh inner table view:
cell.contentView.tableView.dataSource = self
// This is needed for dequeueing to succeed:
cell.contentView.tableView.registerClass(InnerTableViewCell.class, forCellReuseIdentifier: innerCellIdentifier)
cell.contentView.tableView.reloadData()
//^THIS TRIGGERS A CALL TO THIS FUNCTION, ON THE
// INNER TABLE VIEW (PATH [B] BELOW)
return cell
}
else {
// (A.2) NORMAL CELL
let cell = tableView.dequeueReusableCellWithIdentifier(normalCellIdentifier, forIndexPath: indexPath) as! NormalTableViewCell
// (configure cell)
return cell
}
}
else {
// [B] INNER TABLE VIEW
let cell = tableView.dequeueReusableCellWithIdentifier(innerCellIdentifier, forIndexPath: indexPath) as! InnerTableViewCell
// (configure cell)
return cell
}
}
... но я бы сильно спорить против того, представления таблицы внедренного внутри ячейки в целях другой таблицы. По крайней мере, убедитесь, что просмотр внутренней таблицы не требуется прокручивать (т. Е. Содержащая ячейка достаточно высока, чтобы отображать все строки, а сама таблица не имеет прокрутки).
https://github.com/angelvasa/AVLighterTableViewController –