自定义tableViewCell高度

用户名

所以我试图在UITableView中设置3个不同的tableView单元格,每个单元格具有不同的高度。我想知道如何返回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

    }
}
哈姆扎·安萨里(Hamza Ansari)
  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
    }

  }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章