2013-01-03 163 views
-2

tutorial說我應該使用: FBProfilePictureView我們可以只使用正常的imageView的臉譜照片?

好了,說我想用普通的ImageView,然後下載圖像URL。我將如何獲得該imageURL?

+2

有一點上下文會有所幫助。你首先在談論什麼教程? –

+0

補充說。好吧,爲什麼這不是一個真正的問題,因爲我得到了一個非常好的答案,我真的使用了 –

回答

1

以下代碼直接從FBProfilePictureView實現中獲取。我只保留了基本的東西,允許您下載個人資料圖片並將其存儲在普通的UIImageView中。

#import "FBURLConnection.h" 
#import "FBRequest.h" 

//... 

UIImageView * imageView = nil; 
NSString * profileID = @"123456"; // the profile ID of the user you need to retrieve the image of; 
FBURLConnectionHandler handler = ^(FBURLConnection *connection, NSError *error, NSURLResponse *response, NSData *data) { 
    if (!error) { 
     imageView.image = [UIImage imageWithData:data]; 
    } 
}; 

NSString *template = @"%@/%@/picture";  
NSString *urlString = [NSString stringWithFormat:template, 
          FBGraphBasePath, 
          profileID]; 
NSURL *url = [NSURL URLWithString:urlString]; 

[[FBURLConnection alloc] initWithURL:url 
        completionHandler:handler]; 

不過我覺得FBProfilePictureView的方式比使用普通UIImageView更方便。你爲什麼不想用它?

+0

因爲我已經實現了一個ImageView類的緩存和東西。 –

+0

另外我用你的解決方案。我只是要求更大的圖片。 –

+0

它的工作:)謝謝。 –

相關問題