【发布时间】:2011-05-01 16:13:02
【问题描述】:
由于一些奇怪的过度发布,我已经挣扎了好几天。
我的 tableView 类型有点不同,所以不能使用NSFetchControllerDelegate。
实际上每行三个缩略图视图可以触摸。
所以不能用didSelectRowAtIndexPath。
问题是在执行补丁之后。对NSManagedObject的第一次访问返回自
fetchedResultController objectAt indexPath 工作......但第二次尝试访问已释放的对象,这意味着对象已经被过度释放。
但更让我抓狂的是TableViewCellForRowAtIndexPath 中完全相同的功能始终有效。
#pragma mark AlbumListViewCellSelectionDelegate ==> my custom delegate method****
- (void)albumContentsTableViewCell:(AlbumLibViewCell *)cell
selectedPhotoAtIndexType:(NSUInteger)index {
//[self fetch];
NSLog(@"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];
}
同样的功能,但每次都没有问题
- (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
对这种情况的任何想法都可能会有所帮助 提前感谢大家。
【问题讨论】:
-
代码中的哪一行产生了错误?
-
您得到的确切错误是什么?
标签: iphone ios core-data nsmanagedobject