ios - 在 IOS 中使用 Storyboard Identifier 实例化 ViewController

标签 ios objective-c

我正在开发一个 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]

}

enter image description here

我的代码有问题吗?我应该怎么办 ? 提前致谢

最佳答案

这里的问题是您正在引用尚未创建的 socket 。我会尝试将用户模型添加为 View Controller 的属性(或为此使用某种中间 Controller ),在上面的函数中设置用户属性,然后在 viewDidAppear 中设置所有的文本适本地使用用户模型进行控制。

如果您在 viewDidAppear 函数上执行此操作,您可以确定所有 View 都已实例化。毕竟,这也是更好的设计;为什么您的 LoginViewController 类需要了解 profileViewController 的内部结构?以这种方式封装逻辑将导致更少的问题。

希望这有帮助。

关于ios - 在 IOS 中使用 Storyboard Identifier 实例化 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29280561/

相关文章:

iphone - 如何将坐标从英寸转换为像素?

iOS 7 使用 UIPickerView 打开 UITableViewController 速度慢

ios - 仅在测试目标中使用自定义字体?

html - 网页在 iOS 中有很大的右边距

ios - 在 swift (iOS) 中为按钮设置动画时如何移动按钮目标/手势识别器?

iphone - 如何在一个项目中一起使用 2 个可达性类?

iphone - iOS:在 iOS 中处理数据库的最佳方式是什么?

ios - 更改属性 TextView 中一个单词的颜色(objective-c)

ios - 了解一个基本的 Swift 编译器错误

ios - 在没有唯一识别 ID 的情况下禁止社交 iOS 应用程序中的问题用户?