2012-03-24 6 views
2

scrollView에 imageView가 포함되어 있습니다. imageView는 인터넷에서 (flickr API를 통해) 다운로드해야하므로이 문제를 처리 할 수있는 스레드를 추가해야합니다. 그러나 이미지 다운로드가 끝나면 어떻게해야합니까? 이미지 뷰를 다시로드하려면 어떻게해야합니까? 여기에 제 코드가 있습니다.iOS에서 내보기를 다시로드하는 방법

실제로 작동 중입니다. 하지만 imageView의 크기는 (0, 0)입니다. 어떻게 해결할 수 있습니까?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    if (!self.myImage) 
    { 
     UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     [spinner startAnimating]; 
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:spinner]; 
     dispatch_queue_t downloadQueue = dispatch_queue_create("flickr downloader (photo)", NULL); 
     dispatch_async(downloadQueue, ^{ 
      NSData* data = [NSData dataWithContentsOfURL:[FlickrFetcher urlForPhoto:self.photo format:FlickrPhotoFormatLarge]]; 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       self.myImage = [UIImage imageWithData:data]; 
       [self.imageView setImage:self.myImage]; 
       [self viewDidLoad]; 
       [self viewWillAppear:NO]; 
       NSLog(@"imageViewSet!"); 
       self.navigationItem.rightBarButtonItem = nil; 
      }); 
     });  
     dispatch_release(downloadQueue); 
    } 
    else 
    { 
     NSString* imageTitle; 
     if ([[self.photo objectForKey:@"title"] length] > 0) 
      imageTitle = [self.photo objectForKey:@"title"]; 
     else if ([[self.photo valueForKeyPath:@"description._content"] length] > 0) 
      imageTitle = [self.photo valueForKeyPath:@"description._content"]; 
     else imageTitle = @"Unknown"; 
     [[self navigationItem] setTitle:imageTitle]; 
     self.scrollView.delegate = self; 
     self.scrollView.contentSize = self.imageView.image.size; 
    } 
} 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
{ 
    return self.imageView; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 

    [super viewWillAppear:animated]; 
    double scale = self.imageView.bounds.size.width * 1.0/self.myImage.size.width; 
    if (scale > self.imageView.bounds.size.height * 1.0/self.myImage.size.height) 
     scale = self.imageView.bounds.size.height * 1.0/self.myImage.size.height; 
    NSLog(@"imgview%g, %g",self.imageView.bounds.size.width, self.imageView.bounds.size.height); 
    NSLog(@"img%g, %g",self.myImage.size.width, self.myImage.size.height); 
    self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height); 
    [self.scrollView setZoomScale:scale]; 
} 
+0

'dispatch_release (downloadQueue);'를 주석 처리하면 작동합니까? 블록이 실행되기 전에 디스패치 큐를 해제한다고 생각합니다. – Costique

+0

시도했습니다. 아직도 일하지 않고있다. – yoyosir

답변

1

일반적인 방법은 호출하는 것입니다 :

[self.imageView setNeedsDisplay]; 

편집

추가하기 : 그냥 실현

당신은 이미지보기 여전히 (0,0)는 말했다. the docs :

이미지 속성을 설정해도 UIImageView의 크기는 변경되지 않습니다. 이미지 크기와 일치하도록보기의 크기를 조정하려면 크기를 맞 춥니 다.

+0

나는 그것을 시험해 보았다. 나는 [self viewWillAppear : NO]를 대체했습니다. with [self.imageView setNeedsDisplay]; 하지만 작동하지 않습니다. – yoyosir

+0

콘솔에 무엇인가 기록되어 있습니까? 또한 해당 라인을 실행하고 있습니까? 디버거에서 멈출 수 있습니까? – user1118321

+0

2012-03-24 14 : 13 : 49.451 톱 페이지 [1511 : f803] imgview320, 367 2012-03-24 14 : 13 : 49.452 톱 페이지 [1511 : f803] img0, 0 – yoyosir

관련 문제