ios - Swift:返回 UItable View 委托(delegate)和数据源

标签 ios swift uitableview

我有一个主视图 Controller ,它是 TableView Controller 。我有两个 nib 文件。其中一个 Nib 包含一个 TableView 。我想将数据保存在该 TableView 中。我很困惑如何将 UItable View 委托(delegate)和数据源从 nib 文件返回到 mainView。

这是我的代码:

var participationList : ["Apple","Dog","cat","Mat"]
 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    if  indexPath.row == 0
    {
      //first cell
    }
    if indexPath.row == 1
    {
      let cell : ActivitySecondTableViewCell = (NSBundle.mainBundle().loadNibNamed("ActivitySecondTableViewCell", owner: self, options: nil).first as? ActivitySecondTableViewCell)!
      cell.textLabel?.text = self.participationList[indexPath.row]

        return cell
    }

    let cell : ActivitySecondTableViewCell = (NSBundle.mainBundle().loadNibNamed("IncentiveActivitySecondTableViewCell", owner: self, options: nil).first as? IncentiveActivitySecondTableViewCell)!
    return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return 2

}

这是我的主 TableView Controller ,我从这里返回单元格。细胞在这里清楚地显示。 ActivitySecondTableViewCell 包含其中的 TableView 。

这是我的 Nib :

class ActivitySecondTableViewCell: UITableViewCell,UITableViewDelegate {

    @IBOutlet weak var CellTableView: UITableView!
    override func awakeFromNib() {
        super.awakeFromNib()
        self.CellTableView.delegate = self
        // Initialization code
    }

    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "Required Health Activities for 2017"
    }
    func tableView(tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
        if let headerTitle = view as? UITableViewHeaderFooterView {
            headerTitle.textLabel?.textColor = UIColor.redColor()
        }
    }
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    }

我既看不到 Activitysecond 单元格中的标题,也看不到数据。我怎样才能获得它们??

最佳答案

确保您的第一个 tableview 中有超过 2 行,然后使用 UITableViewDataSource 继承 secondTableView 单元格并提供一些 numberOfRows 只是为了检查并在 cellForRowAt 中返回 UITableViewCell 并检查您是否可以看到正在发生的事情。

关于ios - Swift:返回 UItable View 委托(delegate)和数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44223543/

相关文章:

ios - TableView 在数据加载之前出现

ios - APNS 通知 TTL

ios发送没有附件的邮件

ios - UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误

ios - 使用 NSFetchedResultsController 时出现奇怪的删除行为

iphone - 展开 UITableViewstylePlain 中的 UITableView 单元格

javascript - iOS JS 类对象注入(inject) WebView

ios - Storyboard 中 UIViewController 上的异常栏。它是什么?

ios - JSON序列化错误

ios - 如何将文本放在场景包中的节点上?