У меня есть следующий код, который принимает массив nsdictionaries, который содержит путь к uiimage и добавляет их один за другим в uiscrollview.Как получить изображение uiimage, отображаемое в uiscrollview?
- (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. Я посмотрел на другие вопросы, но они кажутся сложными.
Может ли кто-нибудь, пожалуйста, направить меня? Я довольно новичок в uiscrollviews.
Спасибо