2012-11-30 62 views
1

下載UIImages我試圖下載一款用於一些圖片以這樣的方式來自收件箱

-(void)catchTheImage{ 

NSString *title = [[NSUserDefaults standardUserDefaults]objectForKey:@"Folder3"]; 
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager]; 
NSString *filename2 = [NSString stringWithFormat:@"/%@photofile.png.%ld", title, (long)sharedSingleton.tagNumber]; 

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename2]]; 

[restClient loadFile:filename2 intoPath:tmpPngFile]; 

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(lf) userInfo:nil repeats:NO]; 

} 

-(void)lf{ 

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename2]]; 
UIImage* image = [UIImage imageWithContentsOfFile:tmpPngFile]; 
photoView.image = image; 
} 

我知道計時器是不是一個好主意,但它只是嘗試。 TagNumber可以是1,2或3,因爲Dropbox上的圖像是3,但圖像不顯示。我認爲他們沒有保存在文件夾中。可能是我的NSTemporaryDirectory是如何工作的誤解......

+0

擺脫計時器。您需要實現在文件實際下載時調用的Dropbox委託方法。您將在該位置從臨時目錄加載圖像。 – rmaddy

回答

3

是的,你需要實現Dropbox的委託方法將返回關於你的加載過程狀態

這裏是

- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath; 
// Implement the following callback instead of the previous if you care about the value of the 
// Content-Type HTTP header and the file metadata. Only one will be called per successful response. 
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath contentType:(NSString*)contentType metadata:(DBMetadata*)metadata; 
- (void)restClient:(DBRestClient*)client loadProgress:(CGFloat)progress forFile:(NSString*)destPath; 
- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error; 

和在你的情況下:

- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath contentType:(NSString*)contentType metadata:(DBMetadata*)metadata { 

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename2]]; 
UIImage* image = [UIImage imageWithContentsOfFile:tmpPngFile]; 
photoView.image = image; 

} 


- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error { 

    [[[UIAlertView alloc] initWithTitle:@"Oops!!!" message:@"Try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show]; 
} 
+0

你有沒有試過? – Bala

+0

是的,很好,謝謝 – Alessandro