我正在开发一个 iOS 应用程序,该应用程序允许用户使用其 Facebook 帐户登录。 我们登录的用户想要推送填充有用户数据的配置文件 ViewController ; 抱歉这么长的初步准备工作。
问题是当我使用 instantiateViewControllerWithIdentifier
方法启动配置文件 View Controller 时。它的导出组件都是nil
这是我遇到问题的代码
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
profileViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CGProfileViewController"];
profileViewController.fbProfilePictureView.profileID=user.objectID;
profileViewController.nameLabel.text=user.name;
profileViewController.locationLabel.text=user.location.location.city;
// [self presentViewController:profileViewController animated:YES completion:nil]
}
我的代码有问题吗?我应该怎么办 ? 提前致谢
最佳答案
这里的问题是您正在引用尚未创建的 socket 。我会尝试将用户模型添加为 View Controller 的属性(或为此使用某种中间 Controller ),在上面的函数中设置用户属性,然后在 viewDidAppear 中设置所有的文本适本地使用用户模型进行控制。
如果您在 viewDidAppear
函数上执行此操作,您可以确定所有 View 都已实例化。毕竟,这也是更好的设计;为什么您的 LoginViewController 类需要了解 profileViewController
的内部结构?以这种方式封装逻辑将导致更少的问题。
希望这有帮助。
关于ios - 在 IOS 中使用 Storyboard Identifier 实例化 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29280561/