ios - 如何从嵌套数组/字典 iOS 7 中获取值

标签 ios multithreading uitableview dictionary

我从字典中获取值并需要在 UITableView 中显示,但一切正常。

在某些地方它停止运行并显示线程

-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xbfa7670

下面的代码,我用来获取值..

[NSString stringWithFormat:@"%@",[[pageCat1 valueForKeyPath:@"img3"] objectAtIndex:indexPath.row]]

我的值在字典中正确提取但显示延迟?

pageCat (
    {
    img3 = "http://xxx.in/images/page_cat_img/75x75/4.jpg";
    name = "PVC Flexible Wires";
    page =         (
                    {
            id =                 {
                text = 1;
            };
            img4 = "http://xxxx.in/images/page_img/75x75/1.jpg";
            name = "SINGLE CORE FLEXIBLE WIRES ABOVE 6 SQMM";
        },
                    {
            id =                 {
                text = 72;
            };
            img4 = "http://xxx.in/images/page_img/75x75/72.jpg";
            name = "SINGLE CORE FLEXIBLE WIRES BELOW 6 SQMM";
        }
    );
},
    {
    img3 = "http://xxx.in/images/page_cat_img/75x75/3.jpg";
    name = "Bare Copper Wires";
    page =         {
        id =             {
            text = 29;
        };
        img4 = "http://xxx.in/images/page_img/75x75/29.jpg";
        name = "Tinned Copper Fuse Wires";
    };
},
    {
    img3 = "http://xxx.in/images/page_cat_img/75x75/48.jpg";
    name = "Properties of Wire";
    page =         {
        id =             {
            text = 85;
        };
        img4 = "http://xxx.in/images/page_img/75x75/85.jpg";
        name = "Wires - Normal, HR - PVC, FR, FRLS & Zero Halogen";
    };
}

)

实际看日志值,有数组和一组值。。我找不到它是什么形式的。。

谁能帮我找到解决方案??

谢谢, 亚日

最佳答案

它看起来像 [pageCat1 valueForKeyPath:@"img3"] 返回一个 NSString 而不是你期望的 NSArray

在应用 objectAtIndex 之前确保它返回一个 NSArray:

pageCat1 似乎是一个 NSArray,所以你需要这样写:

NSString *path = pageCat1[0][@"img3"];

...

关于ios - 如何从嵌套数组/字典 iOS 7 中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24058376/

相关文章:

FB 点赞/Twitter 关注/Youtube 订阅的 iOS 游戏币

ios - 是否可以通过捕获 QR-Code 自动连接到 WiFi?

c++ - 如何在线程中更新 QCustomPlot 数据?

android - 使用 Otto 从 GcmListenerService 刷新列表适配器

c# - 在 C# 中应用程序结束之前计时器不会触发

ios - 切换方向时从堆栈 View 中删除的元素

ios - TableView 分割动画转场

ios - 配置自定义 UITableViewCell 时如何传递参数

ios - 让线程进入休眠状态但保持动画继续 - 这可能吗?

iOS - 如何在滚动 UITableView 时减少 UINavigationBar titleView 的 alpha?