我有一个问题,当我连续刷新tableView
超过5-6(+/-)次时,我在以下方法中执行错误访问:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *messages = [HumanResponse allAcceptedRecords];
if (messages != nil && messages.count > 0) {
CoreDataPhotoRecord *photoDetails = (CoreDataPhotoRecord *)messages[indexPath.row];
if (photoDetails != nil) {
==> HERE==> if (photoDetails.message != nil) {
if (photoDetails.message.flag.integerValue == FLAG_NOT_HANDLED) {
return YES;
}
}
}
}
return NO;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
id globalCell;
CoreDataPhotoRecord *photoDetails = nil;
if (self.searchDisplayController.isActive) {
photoDetails = self.searchResults[indexPath.row];
}
else {
NSArray *results = [HumanResponse allAcceptedRecords];
if (results.count > 0) {
photoDetails = results[indexPath.row];
}
}
==> HERE==> if (photoDetails != nil && photoDetails.message != nil && [self isNormanMessageCell:photoDetails.message.type.integerValue]) {
MessageCell *cell = (MessageCell *)[tableView dequeueReusableCellWithIdentifier:kMessageCellID
forIndexPath:indexPath];
if (cell == nil) {
cell = (MessageCell *)[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kMessageCellID];
}
if (tableView.isEditing) {
[cell setSelectionStyle:UITableViewCellSelectionStyleDefault];
} else {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
相关方法(我猜):
+ (NSArray *)allAcceptedRecords
{
// Permanent
NSArray *results = [CoreDataPhotoRecord MR_findAllSortedBy:@"message.originalDate"
ascending:NO
withPredicate:[NSPredicate predicateWithFormat:@"message.delete_message == %@", @NO]];
return results;
}
我不知道这里有什么问题,因为我总是在检查这个变量是不是nil,所以它一直在崩溃? 正如我所说,对于前5-6次(+/-),它不会崩溃但是在之后再次尝试会使其崩溃。 我错过了什么?