当我滚动 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/