0

我的应用程序在应用程序加载时不断崩溃,罪魁祸首是这条线:

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;
}
4

1 回答 1

0

错误消息告诉您,您正在将 objectAtIndex: 发送到字典对象,而不是数组。

你有 :

  • 错误的声明或
  • 内存问题(重用空闲内存)
于 2012-08-20T16:34:38.583 回答