ios - ios中的照片序列是混合的

标签 ios objective-c uitableview uiscrollview sdwebimage

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

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

最佳答案

关于ios - ios中的照片序列是混合的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28313854/

相关文章:

c++ - 在 cocos2d-x 的斜杠屏幕中隐藏状态栏

ios - 在 Swift 中检测 GMSPolyline 上的点击?

ios - Swift 通用变量 fatal error : unexpectedly found nil while unwrapping an Optional value

objective-c - 8192x8192 UIView 滞后

ios - 为什么我不能更改 UITableView 的自定义类?

ios - 框架架构 : Specify NSBundle to load . 来自单例初始化期间的 plist 文件

ios - 如何使用 iCarousel 淡出 currentItem 之前的所有项目?

iphone - UIImage 未加载但文件存在

ios - 获取耗时作为 UILabel (objective-c)

ios - 为什么 UITableViewCell 在滚动可用单元格后显示错误数据?