uiimage へのパスを含む nsdictionaries の配列を取り、それらを uiscrollview に 1 つずつ追加する次のコードがあります。
- (void)displayAssets:(NSArray*)postAssets //configured for search
{
for (UIView *v in self.scrollview.subviews) {
[v removeFromSuperview];
}
CGRect workingFrame = self.scrollview.frame;
workingFrame.origin.x = 0;
self.scrollview.delegate = self;
// self.scrollview.contentInset=UIEdgeInsetsMake(10.0,0.0,10.0,0.0);
NSString *pathOfNoImageFile = [[NSBundle mainBundle] pathForResource:@"noimage" ofType:@"png"];
if (postAssets == nil || [postAssets count] == 0) {
UIImage *noImage = [UIImage imageWithContentsOfFile:pathOfNoImageFile];
UIImageView *imageview = [[UIImageView alloc] initWithImage:noImage];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[self.scrollview addSubview:imageview];
}
else
{
//at this moment we have an actual NSArray/NSDictionarry of images that has keys etc.
for (NSDictionary *asset in postAssets) //we have to differentiate between images and videos in future
{
//ASSUMING FIRST VALUE IN ASSETS IS AN Image THIS WILL NEED REFACTORING FOR VIDEOS LATER
NSString * assetID = [asset valueForKeyPath:@"id"];
NSString * imageURL = [NSString stringWithFormat:@"%@post/7777/images/%@.jpg", WEB_SERVICE_BASE_URL, assetID];
UIImage *waitingImage = [UIImage imageWithContentsOfFile:pathOfNoImageFile];
UIImageView *imageview = [[UIImageView alloc] init];
[imageview setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:waitingImage];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[self.scrollview addSubview:imageview];
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
}
[self.scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];
}
// [[self tableView] reloadData];
}
同じファイルの別の関数で私がやろうとしているのは、最初の uiimage または現在表示されている uiimage を取得することであり、そうすることができません。Uiscrollview には、個々のビューにドリルダウンして uiimage を取得できる方法がないようです。私は他のSOの質問を見てきましたが、複雑に思えます。
誰かが私を案内してもらえますか?私はuiscrollviewsにかなり慣れていません。
ありがとうございました