【发布时间】:2011-09-13 08:22:37
【问题描述】:
我有一个如下所示的 NSArray:
![在此处输入图片描述][1]
我需要创建一个 NSArray,其中包含我发布的数组中 4 个字典中每个字典的第一个 URL。然后我将这些设置为单元格的文本信息,objectAtIndex:indexPath.row
【问题讨论】:
标签: iphone objective-c cocoa-touch uitableview nsarray
我有一个如下所示的 NSArray:
![在此处输入图片描述][1]
我需要创建一个 NSArray,其中包含我发布的数组中 4 个字典中每个字典的第一个 URL。然后我将这些设置为单元格的文本信息,objectAtIndex:indexPath.row
【问题讨论】:
标签: iphone objective-c cocoa-touch uitableview nsarray
不就是数组数组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
【讨论】:
NSArray *components = [urlString componentsSeparatedByString:@"?"]; NSString *newString = [components objectAtIndex:0];