我的代理人创建的ALAsset的所有权存在问题。我的委托是一个模态视图,当它被解除时,它返回一个ALAsset,但资产需要比委托更长。
在委托回调中,我只需将ALAsset放在NSMutableArray中,该NSMutableArray由我的应用程序的控制单例[OrderManager sharedOrderManager]
-(void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingPictureWithAsset:(ALAsset *)asset
{
[[[[OrderManager sharedOrderManager] currentOrder] assets] addObject:asset];
}
稍后,(在委托被解雇后)我使用数组中的资产构建表视图
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Photos View Cell Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *imageButton;
imageButton = (UIButton *)[cell.contentView viewWithTag:kImageButton_TAG];
ALAsset *imageAsset = [[[[OrderManager sharedOrderManager] currentOrder] assets] objectAtIndex:indexPath.section];
[imageButton setImage:[UIImage imageWithCGImage:[asset aspectRatioThumbnail]] forState:UIControlStateNormal];
return cell;
}
当然,由于委托不再存在,并且委托是资产的所有者,*imageAsset
现在是一个零指针。
我的问题是,如何将我的表视图控制器或我的sharedOrderManager
作为ALAsset的所有者?
编辑:澄清一下,我正在使用ARC。
答案 0 :(得分:0)
检查NSMutableArray*
返回的assets
是否已初始化(可能是单例实现或之后调用的任何其他方法)。
看起来是nil
而不是addObject:
,objectAtIndex:
也可以返回任何内容。 NSMutableArray
保留添加的对象,在您自己过度发布之前不应该释放它们。