照片序列混合在 ios 中

sequence of photos are mixed in ios

我有一组动态照片。当我试图将它放在水平 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];

当我尝试同步获取照片时,我得到了我需要的东西,但它被冻结了。

我真的推荐使用 UICollectionView 来水平滚动视图。 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionView_class/index.html