UITableView 快速获取 titleForHeadersInSection

2024-05-17

我想在 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;
}

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

self.tableView(tableView, titleForHeaderInSection: 部分)

例如,使用您的代码:

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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UITableView 快速获取 titleForHeadersInSection 的相关文章

随机推荐