我從API這樣的響應特性:如何設置頁眉部分的標題從INDEXPATH.ROW
[{
"name":"apple"
"type": "Fruit"
"taste": sweet
}
{
"name":"lemon"
"type": "Fruit"
"taste": "not tasty"
}]
,現在我想設置一節的標題爲名UITable的視圖。
爲了這個,我已經在我的視圖控制器稱此爲:
var modelclass = [FruitsModelclass]()
override func viewDidLoad()
{
self.loaddata()
}
func loaddata()
{
//here i have called the API and sucessfully get the response in data and assign as
self.modelclass = data
self.tableView.reloadData()
}
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
let cell = tableView!.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath!) as FruitCell
let model = self.Modeldata[indexpath.row]
cell.textlabel.text = model.name
return cell
}
我這是怎麼設置的名到cell.How可我設置爲我headerSection ??有很多我的Api中的json對象不是固定的。在這裏,我只提出了兩個任何人都可以幫助我.. ??
你想在tableview的頭部渲染什麼樣的數據? – tofucodes
我認爲在嘗試做這些之前,你已經擁有了所有的tableView委託方法了嗎?即numberOfRowsInSection,numberOfSections和重寫func tableView(tableView:UITableView,titleForHeaderInSection節:Int) - > String? –
是的,我有他們,但請指導我如何做到這一點 – Sam