我的应用程序在应用程序加载时不断崩溃,罪魁祸首是这条线:
cell.textLabel.text = [[self.searchResults objectAtIndex:[indexPath row]] valueForKey:@"payment_frequency"];
我得到的错误是:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8a538e0'
self.searchResults 确实有 4 个对象,因为它是一个数组。每个对象如下:
{
50316462547c6dbdf2000005 = {
"created_at" = "2012-08-19T17:10:42-0500";
id = 50316462547c6dbdf2000005;
"payment_frequency" = "One Time";
"user_id" = 1;
};
50316462547c6dbdf2000005 = {
"created_at" = "2012-08-19T17:10:42-0500";
id = 50316462547c6dbdf2000005;
"payment_frequency" = "One Time";
"user_id" = 1;
};
50316462547c6dbdf2000005 = {
"created_at" = "2012-08-19T17:10:42-0500";
id = 50316462547c6dbdf2000005;
"payment_frequency" = "One Time";
"user_id" = 1;
};
50316462547c6dbdf2000005 = {
"created_at" = "2012-08-19T17:10:42-0500";
id = 50316462547c6dbdf2000005;
"payment_frequency" = "One Time";
"user_id" = 1;
};
}
这是完整的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SearchResultsViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[self.searchResults objectAtIndex:[indexPath row]] valueForKey:@"payment_frequency"];
return cell;
}