我想最后一个单元格/行(mapView)填充下面的空白区域.
我的tableviewcontroller代码
class CustomTableViewController: UITableViewController { let fakeArray = ["Row1","Row2","Row3"] // Array can contains more items override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int { return fakeArray.count+1 } override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { if(indexPath.row != fakeArray.count){ let cellIdentifier = "TestTableViewCell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,forIndexPath: indexPath) as! TestTableViewCell cell.rowName.text = fakeArray[indexPath.row] return cell }else{ let cellIdentifier = "MapTableViewCell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,forIndexPath: indexPath) as! MapTableViewCell return cell } } override func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { if(indexPath.row != fakeArray.count){ return 44 }else{ return 80 } } }
有时我会在地图前显示更多行.所以下面的空白区域会有所不同.其中空白空间也会因iPhone屏幕尺寸而异.
解决方法
您需要确定您有多少空白空间,然后将地图单元格的高度设置为该空间.
首先,将表视图本身的顶部和底部约束到superview,以确保它占据整个屏幕.
表格视图的可见高度为:
self.tableView.bounds.size.height
在heightForRowAtIndexPath中,计算地图单元格上方单元格的高度,并返回该视图与表格视图的可见高度之间的差异:
let otherCellsHeight: CGFloat = fakeArray.count * 44 return self.tableView.bounds.size.height - otherCellsHeight
当然,您还应检查地图单元的计算高度是否为负值或小于某个最小高度,以确保安全:
let availableSpace = self.tableView.bounds.size.height - otherCellsHeight return (availableSpace > 80) ? availableSpace : 80
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。