{
// 1.獲取本地json文件路徑
let jsonPath =NSBundle.mainBundle().pathForResource("MainVCSettings.json", ofType:nil)
// 2.加載json數(shù)據(jù)
let jsonData =NSData(contentsOfFile: jsonPath!)
// 3.序列化json
do{
// throw是Xcode7最明顯的一個(gè)變化, Xcode7之前都是通過傳入error指針捕獲異常, Xocode7開始通過try/catch捕獲異常
let dictArray =try NSJSONSerialization.JSONObjectWithData(jsonData!, options:NSJSONReadingOptions.MutableContainers)
// 遍歷字典時(shí)候需要明確指明數(shù)組中的數(shù)據(jù)類型
for dictin dictArray as! [[String:String]]
{
// 由于addChildVC方法參數(shù)不能為nil, 但是字典中取出來的值可能是nil, 所以需要加上!
addChildViewController(dict["vcName"]!, title: dict["title"]!, imageName: dict["imageName"]!)
}
}catch{
addChildViewController("HomeTableViewController", title:"首頁", imageName: "tabbar_home")
addChildViewController("MessageTableViewController", title:"消息", imageName: "tabbar_message_center")
addChildViewController("DiscoverTableViewController", title:"發(fā)現(xiàn)", imageName: "tabbar_discover")
addChildViewController("PRofileTableViewController", title:"我", imageName: "tabbar_profile")
}
}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注