2011-08-19 3 views
0
내가 흐름 커버

아이폰 응용 프로그램 - 플로우 커버 (커버 플로우) 디스플레이 이미지

나는 이미지를 전달하고 다운로드 시간 이미지까지 웹 서버

에서 흐름 커버에 이미지를로드하고 통합 한 아이폰 앱에

계산 = 0있는 UIImage = 널

여기

나는 실제로 내가 다운로드하고 해당 뷰를

downlo를로드하는 데 시간이 걸리지 않을 것 때문에 분석에 대해 별도의 스레드를 생성 한의 viewDidLoad 또는 viewwillAppear 같은 방법에 이미지를 다운로드하고 있지 않다 완료되면 터치하면 모든 이미지가 표시되지만 다운로드 완료시 이미지를 표시하고 싶습니다.

터치 식 효과를 사용하지 않고 이미지를 프로그램 적으로 표시하는 방법은 무엇입니까?

도움이 당신이 다운로드의 끝을 인식하는 데 도움이 될

답변

1

제안하십시오. NSURLConnection 다운로드는 비동기식이므로 다운로드가 완료되면 알림을 사용하여 메서드를 시작할 수 있습니다. 완성 된 다운로드에서

[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(some_method:) name:@"some_name" object:nil]; 

알림 전송 :

NSNotifications에 대한 관찰자를 추가

- (void) connectionDidFinishLoading:(NSURLConnection *)connection { 
    [[NSNotificationCenter defaultCenter] 
      postNotificationName:@"some_name" object:nil]; 
} 

을 그리고 그 방법으로 시작됩니다 :

-(void)some_method { 
    // add downloaded image to set or smth 
} 
1

사용 ASIHTTP이 http://allseeing-i.com/ASIHTTPRequest/에서 API를 다운로드

하는 .m 파일에 넣어 코드를 코드 .H 파일

#import <UIKit/UIKit.h> 

#import "AFOpenFlowView.h" 

#import "ASINetworkQueue.h" 
#import "ASIHTTPRequest.h" 

@interface cfDemoViewController : UIViewController <AFOpenFlowViewDataSource, AFOpenFlowViewDelegate> { 
    ASINetworkQueue *queue; 
    NSArray *coverImageData; 
} 
@property (nonatomic, retain) NSArray *arX; 

- (void)imageDidLoad:(NSArray *)arguments; 
-(void)requestForImage:(NSUInteger)index; 

@end 

에 넣어 다음과 다음 프로젝트

에 통합 그런 16,

#import "UIImageExtras.h" 

#import "cfDemoViewController.h" 

#import "UIImageExtras.h" 


@implementation cfDemoViewController 

@synthesize arX = _arX; 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSArray *ar=[NSArray arrayWithObjects:@"http://google.com/report_image/2/17", 
       @"http://google.com/report_image/2/16", 
       @"http://google.com/report_image/2/15", 
       @"http://google.com/report_image/2/14", 
       @"http://google.com/report_image/2/13", 
       @"http://google.com/report_image/2/12", 
       @"http://google.com/report_image/2/11", 
       @"http://google.com/report_image/2/10", 
       @"http://google.com/report_image/2/9", 
       @"http://google.com/report_image/2/8",nil]; 

    self.arX=ar; 

    queue=[[ASINetworkQueue alloc] init]; 

    for (int i=0; i < [ar count]; i++) { 
     [(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:@"default.png"] forIndex:i]; 
    } 

    [self requestForImage:0]; 

    [(AFOpenFlowView *)self.view setNumberOfImages:10]; 
} 

-(void)requestForImage:(NSUInteger)index{ 
    if(index>=[self.arX count]) return; 
    ASIHTTPRequest *req=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[self.arX objectAtIndex:index]]]; 
    [req setDidFinishSelector:@selector(requestDone:)]; 
    [req setDidFailSelector:@selector(requestWentWrong:)]; 
    [req setUsername:[NSString stringWithFormat:@"%i",index]]; 
    [req setDelegate:self]; 
    [queue addOperation:req]; 
    [queue go]; 
} 

- (void)requestDone:(ASIHTTPRequest *)request 
{ 
    NSUInteger index=[[request username] intValue]; 
    UIImage *img=[UIImage imageWithData:[request responseData]]; 
    img=[img cropCenterAndScaleImageToSize:CGSizeMake(225, 225)]; 
    [(AFOpenFlowView*)self.view setImage:img forIndex:index]; 

    [self requestForImage:index+1]; 
    // here all requests are downloaded and you want display any msg to user that code goes here. 

} 

- (void)requestWentWrong:(ASIHTTPRequest *)request 
{ 
// NSError *error = [request error]; 
    NSUInteger index=[[request username] intValue]; 
    [self requestForImage:index+1]; 
} 


- (void)imageDidLoad:(NSArray *)arguments { 
    UIImage *loadedImage = (UIImage *)[arguments objectAtIndex:0]; 
    NSNumber *imageIndex = (NSNumber *)[arguments objectAtIndex:1]; 

    // Only resize our images if they are coming from Flickr (samples are already scaled). 
    // Resize the image on the main thread (UIKit is not thread safe). 
    loadedImage = [loadedImage cropCenterAndScaleImageToSize:CGSizeMake(225, 225)]; 

    [(AFOpenFlowView *)self.view setImage:loadedImage forIndex:[imageIndex intValue]]; 
} 

- (UIImage *)defaultImage { 
    return [UIImage imageNamed:@"default.png"]; 
} 

- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index{ 
    NSLog(@"request for index - %d",index); 
} 

- (void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index { 
    NSLog(@" Hello - Cover Flow selection did change to %d", index); 
} 


- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
// return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    return YES; 
} 

@end 

Also Download code From Here.