ios – 如何使最后一行uitableview填充空白区域

ios – 如何使最后一行uitableview填充空白区域,第1张

概述我想最后一个单元格/行(mapView)填充下面的空白区域. 我的tableviewcontroller代码 class CustomTableViewController: UITableViewController { let fakeArray = ["Row1","Row2","Row3"] // Array can contains more items overri 我想最后一个单元格/行(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
总结

以上是内存溢出为你收集整理的ios – 如何使最后一行uitableview填充空白区域全部内容,希望文章能够帮你解决ios – 如何使最后一行uitableview填充空白区域所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1015651.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存