2016-11-21 10 views
-1

サンプルコードがありますが、numberOfRowsInSectionSWIFT 3に存在しないため、セクションごとの行は表示されません。SWIFT 3のUITableViewにセクションとセルを動的に作成する方法

私は現在、FFコードを持っている:

let section = ["pizza", "deep dish pizza", "calzone"] 

let items = [["Margarita", "BBQ Chicken", "Pepperoni"], ["sausage", "meat lovers", "veggie lovers"], ["sausage", "chicken pesto", "prawns", "mushrooms"]] 

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { 

    return self.section[section] 

} 

override func numberOfSections(in tableView: UITableView) -> Int { 
    return self.section.count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) 

    // Configure the cell... 

    cell.textLabel?.text = self.items[indexPath.section][indexPath.row] 

    return cell 
} 

結果:

enter image description here

を誰かが更新さswift 3の正しいコードを表示することができますか?ありがとう!あなたの情報numberOfRowsInsectionについては

+0

下記参照あなたのコードサンプルでそれを持っていない、あなたは 'numberOfRowsInSection'を実装したのですか? – Wes

+0

私はしましたが、xcodeはそれが不明だと言って赤く強調表示しましたが、tableViewが動作する前に_を追加しました。 – ReversedcigoL

答えて

3

swift3に存在し、

override func numberOfSections(in tableView: UITableView) -> Int { 
    return section.count 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return items[section].count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") 
    cell?.textLabel?.text = items[indexPath.section][indexPath.row] 
    return cell! 
} 

感謝:)

+0

私は 'numberOfRowsInSection'が削除されたと考えました。なぜなら、xcodeはそれが不明だと言って、tableviewのインテリセンスでは' numberOfRowsInSection'を見ていないのに、テーブルビューに_を追加すると赤く強調表示していたからです。ありがとう! – ReversedcigoL

+0

うれしいコーディング:) –

関連する問題