【发布时间】:2016-04-08 13:46:58
【问题描述】:
我希望最后一个单元格/行 (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 屏幕尺寸而异。
【问题讨论】:
-
您可以增加最后一行的行高。
-
我会将地图放在表格视图的页脚视图中。
-
您会在地图前显示这么多行以致地图不可见吗?然后呢?
-
@MikeTaverne 是的,我会的。理想情况下,我想要这个案例的标准高度。当我有空的空间时,我想调整单元格的高度来填充这个空间
标签: ios swift uitableview