1つのセクションに1セルとして、空白なヘッダービューとフッタービューでスペーシングすればいい
TableViewDelegateImpl.swift
class TableViewDelegateImpl : NSObject, UITableViewDelegate {
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 44 // 適当なセルの高さ
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 5 // セルの上部のスペース
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 5 // セルの下部のスペース
}
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
view.tintColor = UIColor.clearColor() // 透明にすることでスペースとする
}
func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
view.tintColor = UIColor.clearColor() // 透明にすることでスペースとする
}
}
TableViewDataSourceImpl.swift
class TableViewDataSourceImpl : NSObject, UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1 // 普通はここで表示したいセルの数を返すが、セクションのヘッダーとフッターでスペーシングしているので、固定で1を返す
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return count // 表示したいセルの数
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return cell // 表示したいセル
}
}