0

当我滚动我的 TableView 时,我得到了 EXC_BAD_ACCESS。我听说像 alloc 这样的东西被称为错误,我不知道。这是我的代码:

        -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
            return [[resultsDictionary objectForKey: @"bills"] count];
        }

        - (UITableViewCell *)tableView:(UITableView *)tableView 
                 cellForRowAtIndexPath:(NSIndexPath *)indexPath {

            // Identifier for retrieving reusable cells.
            static NSString *cellIdentifier = @"MyCellIdentifier";

            // Attempt to request the reusable cell.
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

            // No cell available - create one.
            if(cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                              reuseIdentifier:cellIdentifier];
            }


            NSArray *billsArray = [resultsDictionary objectForKey:@"bills"];

            cell.textLabel.text = [NSString stringWithFormat:@"%@", [[billsArray objectAtIndex:indexPath.row] objectForKey:@"name"]];

            return cell;
        }

编辑

我认为错误在这里:

* -[JKArray objectAtIndex:]: 消息发送到释放的实例 0x6a5d030

NSString *cellName = [NSString stringWithFormat:@"%@", [[billsArray objectAtIndex:indexPath.row] objectForKey:@"name"]];
4

2 回答 2

1

它看起来像resultsDictionary一个悬空指针。如果您使用 ARC,则需要在某处对其进行强引用。如果您不使用 ARC,则需要将其保留在某个地方。

于 2012-07-31T18:47:58.707 回答
0

固定的。我的 billsArray 缺少 'self' 实例,就像在 cellForRowAtIndexPath 方法中一样。谢谢大家。

于 2012-07-31T20:17:21.267 回答