如何访问iOS应用程序中Parse函数返回的数组中的值

时间:2014-09-23 21:13:04

标签: ios objective-c arrays parse-platform

我正在iOS应用程序中调用Parse函数,这就是它返回的内容:

(
    "<matchCenterItem: 0x7fbc6b648620, objectId: EixWxvd0kg, localId: (null)> {\n    categoryId = 171485;\n    itemCondition = New;\n    itemLocation = US;\n    maxPrice = 200;\n    minPrice = 150;\n    parent = \"<PFUser: 0x7fbc6b6526a0, objectId: kfEHfG4FUD>\";\n    searchTerm = \"nexus 7 16gb\";\n}",
    "<matchCenterItem: 0x7fbc6b652dd0, objectId: Je1VxP7dPw, localId: (null)> {\n    categoryId = 9355;\n    itemCondition = Used;\n    itemLocation = US;\n    maxPrice = 350;\n    minPrice = 250;\n    parent = \"<PFUser: 0x7fbc6b652ca0, objectId: kfEHfG4FUD>\";\n    searchTerm = \"iphone 5 unlocked\";\n}"
)

格式化有点奇怪,而且我不习惯。我想要做的是让我的表中的每个单元格使用像这样的数组中的相应searchTerm值作为其标题,但我不确定如何正确引用该值。

这是函数本身的调用:

- (void)viewDidAppear:(BOOL)animated
{
    self.mcSettingsArray = [[NSArray alloc] init];

    // Disable ability to scroll until table is MatchCenter table is done loading
    self.mcSettingsTable.scrollEnabled = NO;

    [PFCloud callFunctionInBackground:@"mcSettings"
                       withParameters:@{}
                                block:^(NSArray *result, NSError *error) {

                                    if (!error) {
                                        _mcSettingsArray = result;
                                        [_mcSettingsTable reloadData];
                                        self.mcSettingsTable.scrollEnabled = YES;
                                        NSLog(@"Result: '%@'", result);
                                    }
                                }];

}

我尝试过这样的事情:

cell.textLabel.text = _mcSettingsArray[indexPath.row][@"matchCenterItem"][@"searchTerm"];

但它崩溃了应用并告诉我[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'

1 个答案:

答案 0 :(得分:1)

确保mcSettingsArray声明为强。确保numberOfRowsInSection数据源方法返回self.mcSettingsArray.count。 cellForRowAtIndexPath中的代码应如下所示:

PFObject *item = self.mcSettingsArray[indexPath.row];
NSString *searchTerm = item[@"searchTerm"];
cell.textLabel.text = searchTerm;