ios - 为从服务器加载的数据分配 2 维数组到 1 维数组

标签 ios objective-c xcode

我正在尝试将一个多维数组分配给一个单维数组以用于我的 UITable View 构造。我决定使用循环来节省时间,因为手动添加数组的数据负载非常繁重。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString1 = [[NSString alloc] initWithData:responseData1 encoding:NSUTF8StringEncoding];

    NSLog(@"%@",responseString1);

    SBJsonParser *parser = [[SBJsonParser alloc] init];
    id sample = [parser objectWithString:responseString1];

    for (int i = 0; i < [sample count]; i++) {
        [tableData addObject:[[sample objectAtIndex:i]objectAtIndex:1]];
        NSLog(@"%@",[sample objectAtIndex:i]);
        NSLog(@"%@",[tableData objectAtIndex:i]);
    }


    [alert dismissWithClickedButtonIndex:0 animated:YES];
}

现在“sample”的 NSLog 反射(reflect)数据,但“tableData”的 NSLog 反射(reflect) NULL。

提前致谢

最佳答案

假设tableData是一个空的NSMutableArray,只需使用

[tableData addObject:[[sample objectAtIndex:i]objectAtIndex:0]];

如果您确实想更改tableData而不是构建它,请使用

[tableData replaceObjectAtIndex:i withObject:[[sample objectAtIndex:i]objectAtIndex:0]];

关于ios - 为从服务器加载的数据分配 2 维数组到 1 维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15616781/

相关文章:

ios - 如何使用 Swift 更改 UIButton 的字体

c++ - 如何摆脱 Djinni 生成的不必要函数 - ToString (in Java)/Description (in Objc)?

ios - NSFetchedResultsController 加上 NSBatchUpdateRequest 等于 NSMergeConflict。我做错了什么?

iphone - iPhone 模拟器启动时自动打开 Safari 调试器

xcode - 使用 Homebrew 版本从 Xcode 覆盖 git

iphone - Xib Size - 似乎认为它比实际长

ios - iOS中的主动降噪

ios - UIStoryboard 容器将 IBOutlet 附加到父 ViewController

ios - 使用由两个远点定义的半径绘制的 MKCircle 渲染不正确

objective-c - NSControl 子类无法读取目标?