应用程序在uitableview加载时崩溃

时间:2012-08-20 16:26:20

标签: ios uitableview

我的应用程序在应用程序加载时一直崩溃,罪魁祸首是行:

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

1 个答案:

答案 0 :(得分:0)

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

你有:

  • 错误的声明 或
  • 内存问题(重用可用内存)
相关问题