【问题标题】:Need to get string from NSArray需要从 NSArray 获取字符串
【发布时间】:2011-09-13 08:22:37
【问题描述】:

我有一个如下所示的 NSArray:

![在此处输入图片描述][1]

我需要创建一个 NSArray,其中包含我发布的数组中 4 个字典中每个字典的第一个 URL。然后我将这些设置为单元格的文本信息,objectAtIndex:indexPath.row

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview nsarray


    【解决方案1】:

    不就是数组数组of数组吗? 运行一个简单的循环来做到这一点:

    NSMutableArray *urls = [NSMutableArray array];
    for(NSArray *a in theArray) {
        NSArray *nestedArray = [a objectAtIndex:0];
        // if you need the whole string
        //[urls addObject:[nestedArray objectAtIndex:0]];
        // if you just need the first part of the URL
        NSArray *components = [[nestedArray objectAtIndex:0]
                               componentsSeparatedByString:@"?"];
        [urls addObject:[components objectAtIndex:0]];
    }
    // you got them
    

    【讨论】:

    • 我试过了,但这就是它注销的内容:box.net/shared/static/5e9e0spgb26xzv2cokcu.png。这个日志的括号比最初的少,所以我们去掉了一个数组,但我仍然只需要一个数组作为每个组的第一个 URL;
    • 谢谢,成功了。最后一件事,你能更新最后的代码,让它也影响这些行吗?谢谢! NSArray *components = [urlString componentsSeparatedByString:@"?"]; NSString *newString = [components objectAtIndex:0];
    猜你喜欢
    • 2011-01-05
    • 2013-06-15
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多