我有一系列动态照片。当我试图将其置于水平UIScrollView中时,我失去了照片序列。 UIScrollView位于UITableViewCell中。代码在函数
下运行(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
for (int i = 0; i < [self.attachments count]; i++)
{ [newArr setDictionary:[self.attachments objectAtIndex:i]];
if ([[newArr objectForKey:@"type"] isEqualToString:@"video"]) {
[typeVideo setDictionary:[newArr objectForKey:@"video"]];
self.photoID = [NSString stringWithFormat:@"%@", [typePhoto objectForKey:@"id"]];
self.urlPhotoString = [NSString stringWithFormat:@"%@", [typeVideo objectForKey:@"photo_75"]];
} else {
[typePhoto setDictionary:[newArr objectForKey:@"photo"]];
self.urlPhotoString = [NSString stringWithFormat:@"%@", [typePhoto objectForKey:@"photo_75"]];
self.photoID = [NSString stringWithFormat:@"%@", [typePhoto objectForKey:@"id"]];
}
// self.imageView=[[UIImageView alloc]initWithFrame:CGRectMake(scrollWidth,0,50,40)];
// Get image from URL this code works cool but frozen
// NSURL *url = [NSURL URLWithString:self.urlPhotoString];
// NSData *data = [NSData dataWithContentsOfURL:url];
// self.img = [[UIImage alloc] initWithData:data];
self.btn =[[UIButton alloc]initWithFrame:CGRectMake(scrollWidth,0,50,40)];
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:[NSURL URLWithString:self.urlPhotoString]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize)
{
NSLog(@"donwloading...");
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
{
if (image && finished)
{
self.img = image;
}
}];
scrollWidth=scrollWidth+80;
// self.imageView.image= self.img;
// self.imageView.backgroundColor = [UIColor blackColor];
// self.imageView.contentMode = UIViewContentModeScaleAspectFit;
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumber = [f numberFromString:self.photoID];
[self.btn setTag: [myNumber longLongValue]];
NSString* postID = [NSString stringWithFormat:@"%@#%d", [[self.items objectAtIndex:indexPath.row] objectForKey:@"id"], i];
self.btn.titleLabel.text = postID;
self.btn.titleLabel.hidden=YES;
[self.btn setBackgroundImage:self.img forState:UIControlStateNormal];
[self.gallery addSubview: self.btn];
[self.btn addTarget:self action:@selector(nextPhoto:) forControlEvents:UIControlEventTouchUpInside];
}
[self.gallery setContentSize:CGSizeMake(scrollWidth, 30)];
[postCell.contentView addSubview: self.gallery];
当我试图同步拍照时,我得到了我需要的东西,但它被冻结了。
答案 0 :(得分:1)
我真的建议使用UICollectionView来水平滚动视图。 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionView_class/index.html