Reputation: 859
I'm calling a Parse function from within my iOS app, and this is what it returns:
(
"<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}"
)
The formatting is a bit strange, and one that I'm not used to. What I want to do is have each cell in my table use the respective searchTerm
value in an array like this as its title, but I'm not sure how to refer to the value correctly.
Here's the calling of the function itself:
- (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);
}
}];
}
I've tried something like this:
cell.textLabel.text = _mcSettingsArray[indexPath.row][@"matchCenterItem"][@"searchTerm"];
but it crashes the app and tells me that [__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
.
Upvotes: 0
Views: 59
Reputation: 62676
Make sure that mcSettingsArray
is declared strong. Make sure that the numberOfRowsInSection
datasource method returns self.mcSettingsArray.count
. The code in cellForRowAtIndexPath should look like this:
PFObject *item = self.mcSettingsArray[indexPath.row];
NSString *searchTerm = item[@"searchTerm"];
cell.textLabel.text = searchTerm;
Upvotes: 1