【问题标题】:Creating a FBProfilePictureView in Storyboard在 Storyboard 中创建 FBProfilePictureView
【发布时间】:2014-06-07 17:32:33
【问题描述】:

我使用情节提要编辑器在视图控制器的主视图中创建了一个UIView,并将其类更改为FBProfilePictureView

我创建了一个出口:

@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

我错过了什么?

【问题讨论】:

    标签: objective-c ios facebook-ios-sdk


    【解决方案1】:

    虽然我没有看到FB docs中提到的错误,但补充:

    [FBProfilePictureView class];
    

    到 applicationDidFinishLaunching 成功了。大概是一些运行时魔法。

    【讨论】:

    【解决方案2】:

    除了调用类方法之外,我不会依赖[userImage class]。如果您需要确保userImage 是正确的类型,请使用[userImage isKindOfClass:[FBProfilePictureView class]]。它会让您知道您是否可以将对象视为 FBProfilePictureView。

    【讨论】:

    • 关键是为了让 Storyboard 将其实例化为 FBProfilePictureView,需要此调用。我不确定机制是什么,因为我无法访问源代码。我同意在我与对象交互之前可以添加您的代码以确保安全。
    【解决方案3】:

    解决这个问题的更优雅的方法可能是添加 -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

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-02-03
      • 2012-08-15
      • 2011-12-13
      • 2012-03-10
      • 2016-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      相关资源
      最近更新 更多