防止页脚在 UITableView 中重叠 tableViewCell - Swift

use*_*164 6 uitableview ios swift

我有这个表格视图,它按照我想要的方式工作,但是我有一个问题,即页脚与表格视图中的单元格重叠,如图这个图片

我怎样才能防止这种情况?这是我的页脚代码

   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)
  }
Run Code Online (Sandbox Code Playgroud)

Ali*_*aoi 5

你可以做到这一点,只需制作Grouped如下所示的样式:这里


Art*_*tov -1

尝试重写这个方法

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 44.0
}
Run Code Online (Sandbox Code Playgroud)