some time can't access NSmanagedObject returned form fetchResultController
I have been struggling several days because of some weird overreleased.
My tableView is little bit different type so can't use NSFetchControllerDelegate
.
Actually three thumbnail views in each row which can toucable.
So can't use didSelectRowAtIndexPath
.
The problem is after execution patch. The first access to NSManagedObject
returned from
fetchedResultController objectAt indexPath works ... but second try make access to deallocated object which mean is object is already overreleased.
But the more make me crazy is exact same function in TableViewCellForRowAtIndexPath
is work always.
#pragma mark AlbumListViewCellSelectionDelegate ==> my custom delegate method****
- (void)albumContentsTableViewCell:(AlbumLibViewCell *)cell
selectedPhotoAtIndexType:(NSUInteger)index {
//[self fetch];
NSL开发者_JAVA技巧og(@"select !!!! %i",index);
lastSelectedRow=cell.rowNumber;
//[selectedAssets addObject:[assets objectAtIndex:(lastSelectedRow * imageNoPerRow) + index]];
int selectId =(lastSelectedRow * imageNoPerRow) + index;
if(albumCount >=(selectId+1)){
AlbumTag * album = (AlbumTag *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:selectId inSection:0]] ;
//scrollView
AutoScrollViewController *detailViewController =[[AutoScrollViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed=YES;
detailViewController.selectedMoments = [album.moments allObjects];==> first work but overrelease every second try
detailViewController.initPhotoNumber = 0;
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
same function but every time no problem
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"AlbumLibViewCell";
AlbumLibViewCell *cell = (AlbumLibViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"AlbumLibViewCell" owner:self options:nil];
cell = tmpCell;
tmpCell = nil;
}
cell.backgroundColor =[UIColor blackColor];
cell.rowNumber = indexPath.row;
cell.selectionDelegate = self;
// Configure the cell...
NSUInteger firstPhotoInCell = indexPath.row * imageNoPerRow;
NSUInteger lastPhotoInCell = firstPhotoInCell + imageNoPerRow;
if (albumCount <= firstPhotoInCell) {
NSLog(@"We are out of range, asking to start with photo %d but we only have %d", firstPhotoInCell, albumCount);
return nil;
}
NSUInteger currentPhotoIndex = 0;
NSUInteger lastPhotoIndex = MIN(lastPhotoInCell, albumCount);
for (firstPhotoInCell ; firstPhotoInCell + currentPhotoIndex < lastPhotoIndex ; currentPhotoIndex++) {
AlbumTag *albumCell = (AlbumTag *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:firstPhotoInCell + currentPhotoIndex inSection:0]];
UIImage *thumbnail = albumCell.rpeMomentThumbnail;
NSArray *moments = [albumCell.moments allObjects]; ===> every time works fine
Any idea for this situation might be help appreciate in advance all.
Seems like objects being passed into detailViewController are being released but not retained. You should turn on NSZombies to debug this. If that doesn't work you can track your allocation history using the ObjectAlloc instrument in Instruments.
精彩评论