ios - 用于以编程方式呈现嵌套 JSON 的 Tableview

标签 ios swift uitableview

我有一个代表地址的 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/

相关文章:

objective-c - 以编程方式查找区域

ios - 如何在 UserDefaults swift 中设置枚举数组

ios - 以编程方式用数组中的数据填充 UICollectionView 中的 UICollectionViewCells

swift - 如何快速打开 URL 并在 Safari 中发布数据

ios - 在父 UIViewController 中收到多个 NSNotifications

ios - 如何在使用 tableViews 自调整单元格大小时在运行时更改 TableView 单元格高度?

ios - 如何让 Firebase 动态链接与 App Clips 一起使用?

ios - 使计时器无效并创建新实例

objective-c - 可以将 "sticky" header 添加到分组 TableView 吗?

ios - 如何让 "View All"按钮通过 segue 到下一个 ViewController 显示数据?