自定义 tableViewCell 高度

customize tableViewCell heights

所以我试图在 UITableView 中设置 3 个不同的 tableView 单元格,每个单元格的高度不同。我想知道如何 return 3 个不同的单元格,每个单元格都有自己的自定义高度?

感谢指点或帮助!

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    return 3
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if(section == 0) {
        return 1
    }
    if(section == 1) {
        return 1
    }
    else {
        return 10
    }

}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    switch indexPath.section{
    case 0:
        let myProfile = tableView.dequeueReusableCellWithIdentifier("ProfileHeaderCell") as! VideoTableViewCell



        return myProfile

    case 1:
        let myInfo = tableView.dequeueReusableCellWithIdentifier("AlbumCell") as! AlbumTableViewCell


        return myInfo

      default:
        let cell = tableView.dequeueReusableCellWithIdentifier("TravelBookCell") as! TravelBookTableViewCell


        return cell

    }
}

您可以切换单元格的边框大小。这是开关的情况 0 的示例。

    case 0:
            let myProfile = tableView.dequeueReusableCellWithIdentifier("ProfileHeaderCell") as! VideoTableViewCell

myProfile.frame.size = CGSize(width: /*CGFloat*/, height: /*CGFloat*/)  

            return myProfile
  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    let section = indexPath.section
    if(section == 0) {
      return 20
    }
    if(section == 1) {
      return 30
    }
    else {
      return 50
    }

  }