【发布时间】:2012-11-22 08:28:48
【问题描述】:
您好,我在滚动视图上显示图像时遇到问题。
首先,我使用资产 url 创建新的 UIImageView:
-(void) findLargeImage:(NSNumber*) arrayIndex
{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep;
if([myasset defaultRepresentation] == nil) {
return;
} else {
rep = [myasset defaultRepresentation];
}
CGImageRef iref = [rep fullResolutionImage];
itemToAdd = [[UIImageView alloc] initWithFrame:CGRectMake([arrayIndex intValue]*320, 0, 320, 320)];
itemToAdd.image = [UIImage imageWithCGImage:iref];
[self.scrollView addSubview:itemToAdd];
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Cant get image - %@",[myerror localizedDescription]);
};
NSURL *asseturl = [NSURL URLWithString:[self.photoPath objectAtIndex:[arrayIndex intValue] ]];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];
}
其中 itemToAdd 是接口中定义的 UIImageView:
__block UIImageView *itemToAdd;
并将scrollView定义为一个属性:
@property (nonatomic, strong) __block UIScrollView *scrollView;
然后在我看来WillAppear 我会这样做:
- (void) viewWillAppear:(BOOL)animated {
self.scrollView.delegate = self;
[self findLargeImage:self.actualPhotoIndex];
[self.view addSubview:self.scrollView];
}
但是图像没有出现,我应该在将图像添加到scrollView后刷新self.view,还是应该做其他事情?
【问题讨论】:
-
你检查它是否真的进入了结果块吗?
-
是的,我确定我的方法会进入成功块,如果我将图像发送到另一个视图控制器,它将被显示。
-
__block仅适用于局部变量。你正试图把它放在一个属性上。这没有意义。
标签: iphone ios objective-c-blocks