iphone - iOS - Interface Builder Outlet 未初始化

标签 iphone ios uiviewcontroller interface-builder iboutlet

我在 Interface Builder 中创建了一个 View ,其中包含一些标签和文本作为 IBOutlet。当我从 Storyboard中定义的另一个 View 转到该屏幕时,我可以完美地查看该屏幕。 但是,我有另一个 XIB 和一个关联的 UIViewController,我想从中访问该 View 。因为我的 XIB 不在 Storyboard 中,所以我无法继续下去。相反,我必须以编程方式执行转换。

    PlantDetailViewController *plantDetailVC = [[PlantDetailViewController alloc] init];
    [self.currentNavigationController pushViewController:plantDetailVC animated:YES];

执行此代码时,它会转换到 View ,但 View 只是空白。我已经调试了代码,它进入了 viewDidLoad 和 viewWillAppear,但是我所有的 IBOutlet 都是 NIL....所以屏幕上什么也没有显示!

谁能告诉我为什么它们可能是 NIL 以及如何初始化它们?

谢谢

布莱恩

最佳答案

听起来您好像在说您的 Storyboard中设置了一个 PlantDetailViewController ,以及一些在 Storyboard之外创建的 OtherViewController 。现在,您希望 OtherViewController 实例化在 Storyboard 中设置的 PlantDetailViewController

假设您的 Storyboard名为 MainStoryboard.storyboard

首先,您需要在 Storyboard中设置 PlantDetailViewController 的标识符。您可以在“属性”检查器的“ View Controller ”部分下执行此操作。假设您将其设置为 PlantDetail

然后,在OtherViewController中,这应该可以工作:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PlantDetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"PlantDetail"];
[self.currentNavigationController pushViewController:vc animated:YES];

关于iphone - iOS - Interface Builder Outlet 未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9935612/

相关文章:

iphone - 另一个 View 中的相机预览宽度问题

ios - 之前推送 View Controller 的计时器仍在运行

objective-c - UIScrollView 显示多个带分页的UIView

iphone - iOS 7 导航栏颜色在 iPhone 4 上无法正确显示

iphone - 在新部分的表格 View 中插入一行

php - 将 iPhone 应用程序 (iOS SDK) 连接到 php/MySql 后端的最佳方法是什么

ios - 解析: emailVerified is found nil on iPhone but works fine on Simulator

c# - 如何在 Xamarin C# 中更改字体/颜色/大小

ios - scrollToItemAtIndexPath iOS swift

ios - 如何将相机预览放入 UIImageView?