防止页脚与UITableView中的tableViewCell重叠-Swift [英] Prevent footer overlapping tableViewCell in UITableView - Swift

查看:162
本文介绍了防止页脚与UITableView中的tableViewCell重叠-Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此表视图,该表视图按我希望的方式工作,但是我遇到一个问题,即页脚与表视图中的单元格重叠,如

I have this table view which works how i want it to however i have a problem where the footer overlap the cells in the table view as seen in

如何防止这种情况?这是我的页脚代码

How can i prevent this? This is my code for the footer

   func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {

    let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
    //    self.myTableView.tableFooterView = footerView;
    let sectionString = Array(foodArray.keys)[section]


      for value in caloriesArray[sectionString]! {
        calories += value
       }
       totalCalories += calories

      print(calories)
      print(totalCalories)
      let label = UILabel(frame: CGRectMake(footerView.frame.origin.x - 15, footerView.frame.origin.y, footerView.frame.size.width, 20))

       label.textAlignment = NSTextAlignment.Right

       label.text = "Total Calories: \(calories) "

      footerView.addSubview(label)
       calories = 0
  return footerView
  }

 func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {

  return 20.0
}

@IBAction func addFoodTapped(sender: AnyObject) {


}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


    let sectionString = Array(foodArray.keys)[indexPath.section]

    foodArray[sectionString]?.removeAtIndex(indexPath.row)
    caloriesArray[sectionString]?.removeAtIndex(indexPath.row)
    print(foodArray)
   viewDidAppear(true)
  }

推荐答案

您可以做到,只需制作样式Grouped,如下所示:

You can do that, Just make Style Grouped as shown below:

这篇关于防止页脚与UITableView中的tableViewCell重叠-Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆