[英]Tableview within tableview swift
我需要一个具有UITableView
的视图, 主 UITableView
具有一个具有另一个tableview的单元格。 我已经在情节提要上添加了视图,并在单个viewcontroller中实现了委托和数据源方法。 但是由于我已经设置了内部tableview委托和数据源,因此内部tableview不会调用tableview方法:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell()
switch tableView.tag {
case 1:
if indexPath.section == 0 {
let pendingReportsCell = tableView.dequeueReusableCellWithIdentifier("PendingReportsCell") as! PendingReportsTableViewCell
pendingReportsCell.taxYearTableView.delegate = self
pendingReportsCell.taxYearTableView.dataSource = self
taxTableView = pendingReportsCell.taxYearTableView
taxTableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: "EarliestMonthTaxYearCell")
tableView.tag = (taxTableView?.tag)!
taxTableView?.reloadData()
}
请告诉我替代方法。
在您的自定义单元格类中设置委托和数据源,如下所示:-
class PendingReportsCell: UITableViewCell {
// set the delegate & datasource of taxYearTableView in the init or
// awakefromnib or storyboard.
// I have set it in storyboard and it works for me.
// Implement the datasource and delegate methods of taxYearTableView in this class.
}
调用taxTableView?.reloadData()时,它将调用上述委托和数据源方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.