【发布时间】:2015-01-16 15:12:56
【问题描述】:
我想在 UITableView 的部分设置表头的标题。 swift 中设置部分标题标题的语法是什么。
func tableView( tableView : UITableView, titleForHeaderInSection section: Int)->String
{
switch(section)
{
case 2:
return "Title 2"
break
default:
return ""
break
}
}
func tableView (tableView:UITableView , heightForHeaderInSection section:Int)->Float
{
var title = tableView.titleForHeaderInSection[section];
if (title == "") {
return 0.0;
}
return 20.0;
}
func tableView (tableView:UITableView, viewForHeaderInSection section:Int)->UIView
{
var title = tableView.titleForHeaderInSection[section] as String
if (title == "") {
return UIView(frame:CGRectZero);
}
var headerView:UIView! = UIView (frame:CGRectMake(0, 0, self.tableView.frame.size.width, 20.0));
headerView.backgroundColor = self.view.backgroundColor;
return headerView;
}
【问题讨论】:
-
为什么不使用章节编号而不是标题?
-
其实我想知道获取标题For Header In Section的语法。
标签: uitableview swift swift-playground ios8.1