2016-12-29 13 views
1

私は比較的簡単なコードです。ここでSwift 3のテーブルビューに配列名を渡すことができません

今私はシミュレータで空のテーブルビューを取得しています

override func viewDidLoad() { 
    super.viewDidLoad() 

let path = Bundle.main.path(forResource: "xml", ofType: "plist") 
    if let dict = NSDictionary(contentsOfFile: path!), let arrays = dict.object(forKey: "Complete") as? [String: Any] { 
     self.ansTopics = arrays 
     self.chapters = self.ansTopics.keys.sorted() 
    } 

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

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

...テーブルビューにPLISTに配列のテキストを渡すことができませんplistファイルは

<plist version="1.0"> 
<dict> 
<key>Complete</key> 
<dict> 
<key>Autonomic Nervous System</key> 
<array> 
    <string>Cholinergic</string> 
    <string>Anticholinergic</string> 
</array> 
<key>Peripheral Nervous System</key> 
<array> 
    <string>Central relaxants </string> 
    <string>Peripheral relaxants </string> 
</array> 
</dict> 
<key>Chap</key> 
<array> 
<string>Autonomic Nervous System</string> 
<string>Peripheral Nervous System</string> 
</array> 
</dict> 
</plist> 
+0

'self.chapters'出力は何ですか? –

+1

'self.chapters = self.ansTopics.keys.sorted()'の 'cell.tableView.reloadData()'の後に一度テーブルビューを再読み込みしてみてください –

+0

@NiravD Empty simulator – Nish

答えて

1

ですそれはあなた

let arrays = dict.object(forKey: "Complete") as? Dictionary<String,AnyObject> 

代わりの

助けるかもしれない、このコードを試してみてください
let arrays = dict.object(forKey: "Complete") as? [String: Any] 

おかげ

+0

エラー: "<__>" – Nish

+0

のように、キャストでジェネリックパラメータ "key"を推論できませんでしたDictionary

+0

これで、self.ansTopics = arrays行が不正実行エラー – Nish

関連する問題