2012-08-29 51 views
1

我使用storyboard編輯器在視圖控制器的主視圖中創建了一個UIView,並將其類改爲FBProfilePictureView在Storyboard中創建一個FBProfilePictureView

enter image description here

我創建了一個出口:

@property (weak, nonatomic) IBOutlet FBProfilePictureView *userImage; 

然而,當我指的是userImage對象代碼它報告本身作爲一個UIView。

NSLog(@"userImage class: %@", [userImage class]); 

產地:

2012-08-28 17:52:22.196 FBTestApp[6230:707] userImage class: UIView 

我缺少什麼?

回答

5

雖然我沒有看到FB docs提到的錯誤,並補充說:

[FBProfilePictureView class]; 

要在applicationDidFinishLaunching的伎倆。推測一些運行時間魔法正在進行。

+1

就像一個補充,它現在在文檔中說增加這條線 - https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/personalize/ – StuStirling

0

除了調用類方法之外,我不會依賴​​。如果您需要確保userImage是正確的類型,請使用[userImage isKindOfClass:[FBProfilePictureView class]]。它會讓你知道你是否可以將該對象視爲FBProfilePictureView。

+0

關鍵是,爲了故事板將其實例化爲FBProfilePictureView,這個調用是必需的。我不確定這些機制是什麼,因爲我無法訪問源代碼。我同意在與對象交互之前可以添加您的代碼以確保安全。 –

0

解決此問題的更優雅的方法可能是添加-ObjC鏈接器標記,而不是執行此「運行時魔術」的東西。 Here you can find instructions on how to add the flag!

SDK documentation,它說:

Note: If you've added the -ObjC flag to your linker options, then you don't have to add this code. Adding that flag causes the linker to load all the object files in the Facebook SDK, including the FBLoginView class. If you want to know more about what the -ObjC flag does, you can check out our troubleshooting guide.

它提到FBLoginView,而是根據這個問題的答案,它也適用於FBProfilePictureView:FBProfilePictureView object wont show image

希望這有助於。

相關問題