【发布时间】:2016-01-05 09:32:52
【问题描述】:
我需要在 swift 2.1 中添加填充,以便在每个部分的每个单元格之间添加空间
但我所做的只是为我不想要的部分添加标题。
如何在动态表格单元格之间添加空格?
添加标题的代码如下:
// Set the spacing between sections
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 10
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = UIView()
header.backgroundColor = UIColor.clearColor()
return header
}
这里是创建表格视图的代码:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tableData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//Table view cells are reused and should be dequeued using a cell identifier.
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let rowData = self.tableData[indexPath.row]
cell.textLabel!.text = rowData.name
cell.textLabel!.textAlignment = .Right
if let url = NSURL(string: rowData.img),
data = NSData(contentsOfURL: url)
{
cell.imageView?.image = UIImage(data: data)
}
return cell
}
现在我的表格视图如下所示:
更新代码和表格视图:
【问题讨论】:
-
空间到底应该在哪里?在每个单元格之间?
-
你想增加两个单元格之间的空间?
-
@ChikabuZ 我想在两个单元格之间添加空格
-
@MehulSojitra 是的,我需要在两个单元格之间添加空格
-
使用tableview的委托方法heightForRowAtIndexPath,它将返回单元格的高度。
标签: ios swift spacing tableviewcell cellpadding