objective-c - EXC_BAD_ACCESS 滚动TableView

标签 objective-c ios

当我滚动 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"]];

最佳答案

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

关于objective-c - EXC_BAD_ACCESS 滚动TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11746801/

相关文章:

iOS App蓝牙无法连接外围设备

ios - 无法从其 subview 中获取正确的 UIScrollView 高度

objective-c - 无法从 NSPopUpButton 中删除项目

ios - 如何在 Storyboard 中使用 UICollectionViewController 同时仍支持 ios 5.1?

ios - 如何将按钮操作作为直接命令执行

ios - 使用级联关系删除 Realm 中的对象

objective-c - 绘图的 NSFont 高度

objective-c - iOS 中的 AES256 NSString 加密

ios - 在第二次调用期间将数据填充到方法中的字典时出错

ios - 使用 GL_TRIANGLE_STRIP 绘制圆弧