我有一个代表地址的 JSON 树。像这样的,
- Address Tree
- Address Tree Deeper
- Address Tree Deeper
- Address Tree Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
- Address Tree
- Address Tree Deeper
- Address Tree Deeper
- Address Tree Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
我想用表格显示那棵树,用户可以选择它的 child ,但我不知道如何表示。我的意思是,我们是否应该创建多个 ViewController
(当然还有它在 Storyboard中的场景),然后我们将每一个更深入地推进到 address child?或者我可以通过编程方式创建 UITableView
?
或者有什么方法可以用于这种情况?我考虑重用 viewcontroller,但我没有任何线索。
如有任何帮助,我们将不胜感激。非常感谢!
最佳答案
在您的 IB 中创建 3 个 UITableViewControlle rs(因为它是最大值),如果该字典中有子类别,则相应地推送 View Controller 。
一个你应该如何做的例子:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(yourDictionary[indexPath.row].yourVariable != nil){
let nextViewController = self.storyboard?.instantiateViewControllerWithIdentifier("nextViewController") as! ScoutPage
self.navigationController?.pushViewController(nextViewController, animated: true)
}
}
关于ios - 用于以编程方式呈现嵌套 JSON 的 Tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38965702/