gpt4 book ai didi

UITableView 快速获取 titleForHeadersInSection

转载 作者:IT王子 更新时间:2023-10-29 05:35:03 24 4
gpt4 key购买 nike

我想在 UITableView 的部分设置页眉的标题。 swift 中用于设置节中 header 标题的语法是什么。

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;
}

最佳答案

您可以使用已经在您的类中定义的函数,即:

self.tableView(tableView, titleForHeaderInSection: section)

例如,使用您的代码:

func tableView( tableView : UITableView,  titleForHeaderInSection section: Int)->String {
switch(section) {
case 2:return "Title 2"

default :return ""

}
}

func tableView (tableView:UITableView , heightForHeaderInSection section:Int)->Float
{

var title = self.tableView(tableView, titleForHeaderInSection: section)
if (title == "") {
return 0.0
}
return 20.0
}

关于UITableView 快速获取 titleForHeadersInSection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27011131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com