2017-03-07 66 views
1

我创建了这样一个数组:返回标题从标题从阵列部分,其动态

var PropertiesForSectionFromModel :[String] = [String]() 

和映射数组这个

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.loadData() 
    } 
func loadData() 
{ //Here is a Api call and i have successfully called it. 
    self.PropertiesForSectionFromModel = Array(self.DataSource.map({ 
      (item) -> String in item.labelText 
      })) 
      self.tableView.reloadData() 

      print(self.PropertiesForSectionFromModel) 

     } 

    } 

} 

在这里我得到的打印(自.PropertiesForSectionFromModel) [“名字”,“姓氏”,“出生日期”,“电子邮件”]。这里有四个项目,所以现在应该有四个部分。这些部分本质上是动态的。它可以有更多的部分根据中的项目。PropertiesForSectionFromModel

现在我想将它们设置为titleForHeaderInSection。我曾经做过这样的: `

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
     return self.PropertiesForSectionFromModel[section] 

    } 

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return self.PropertiesForSectionFromModel.count 
    } 

`但标题是不是被人displayed..Can帮我为什么不显示??

+0

你迅速上3个工作? –

+0

不是它的2不是3. – Sam

+0

你能调试和检查你在numberOfSectionsInTableView中获得什么样的计数值吗? –

回答

0

你应该实现以下方法:

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    // return the height of the header, e.g. 50.0 
    return 50.0 
} 
+0

标题中仍然没有显示 – Sam

+0

“PropertiesForSectionFromModel”是否包含条目后是否重新加载tableview? – chengsam

+0

是的,我已经完成self.tableview.reloadData – Sam