如何在表格视图中添加三个表格视图单元格作为子视图?

How to add three tableview cells in a tableview as Subview?

我想添加 2 个单元格,一个作为 header 从前一个表格视图中转出,第二个单元格用于详细信息,例如此原型。

第一个单元格 class "courseCell" 第二个单元格 Class "DetailsTVC"

找了很多方法都行不通希望有人帮忙

I couldn't follow with this instruction
Initialize your custom tableviewcell - CustomCell1 and CustomCell2
Since tableviewcell is a subclass of UIView you can add it as a subview.
  [TableCell addSubview:CustomCell1];
          [TableCell addSubview:CustomCell2];
          cell?.addSubview(<#view: UIView>)
         [cell ?.addSubview(<#view: UIView>)]

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("cell" , forIndexPath : indexPath) as? courseCell


    if cell == nil
    {
        cell = courseCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
    }

    cell?.name.text = object["title"] as! String!
    cell?.location.text = object["Location"] as! String!






    return cell!
}

我不确定为什么你的问题标题提到了 3 而你的问题只提到了 2 但从我根据图像可以理解的情况来看,你似乎希望 header 作为课程的标题并且其余的单元格是课程的详细信息。

要为您的 TableView 创建 header,您可以像创建自定义单元格一样创建自定义 "HeaderCell",然后在指定 Header 的方法中使用它:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
     //set the title, image or whatever you want for your custom header cell
}

现在您可以像往常一样使用另一个自定义 TableView 单元格来显示详细信息。

教程:

http://www.ioscreator.com/tutorials/customizing-header-footer-table-view-ios8-swift

完成它:

TableViewController
 - Tableview
   - TableViewHeader (create a UIView subclass for this view)
   - TableViewContent (datasource)
     - TableViewCell1 (virgin american fligth ...)
     - TableViewCell1 (departs los angeles)
     - TableViewCell1 (arrives new york)

请注意,您的 tableviewController 不需要 XIB 文件