- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 Storyboard 并从如下代码实例化一个 View Controller :
NSLog(@"1");
MyController *vc = (MyController *)[[UIStoryboard storyBoardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"MyController"];
NSLog(@"4");
MyController 类的实现包括以下内容:
- (void)viewDidLoad {
NSLog(@"2");
[super viewDidLoad];
[NSThread sleepForTimeInterval:2];
NSLog(@"3");
}
我希望在运行代码时看到以下输出:
1
2
3
4
但似乎直到我访问 MyController
的 View 时才调用 -viewDidLoad
:
1
4
如果我这样修改第一个:
NSLog(@"1");
MyController *vc = (MyController *)[[UIStoryboard storyBoardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"MyController"];
[vc view]; // Just accessing
NSLog(@"4");
那么它的输出将是:
1
4
2
3
我如何确定我的属性已初始化(-viewDidLoad
已运行)并且我可以为我的 Controller 提供参数?推荐的方法是什么?
最佳答案
您应该编写您的 VC,以便在设置属性之前或之后加载 View 都没有关系。
如果你有这样的属性(property):
@property (nonatomic, copy) NSString *superAwesomeLabelText;
而你需要设置你的超赞标签的文字,有以下内容:
在viewDidLoad
self.superAwesomeLabel.text = (self.superAwesomeLabelText) ?: @"Default lame text";
superAwesomeLabelText
的 setter :
- (void)setSuperAwesomeLabelText:(NSString*)superAwesomeLabelText {
_superAwesomeLabelText = [superAwesomeLabelText copy];
self.superAwesomeLabel.text = superAwesomeLabelText;
}
现在,无论是在设置属性之前还是之后加载 View 都没有关系。
关于ios - 等待 instantiateViewControllerWithIdentifier 完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33620193/
我正在尝试使用下图所示的代码片段实例化 MainStoryBoard.storyboard 中定义的 ViewController。我还为 Controller 分配了一个标识符,但应用程序因图片中显
我正在主 Controller 中加载以下代码。我已经进行了调试,以确保它调用 WebPortalViewController 时没有任何问题。 父 Controller A.viewDidLoad(
我正在使用 Storyboard,我需要使用此方法将 Storyboard中的 View Controller 与 View Controller 同步。我不知道在哪里添加这个方法。如果它自己,我将如
我在将一个 View 推送到另一个 View 时遇到问题并且还发现了代码中的错误,但我已尝试找出解决方案。请参阅下面的代码 print(">") let vc = self.storyboard?.i
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
我有这段代码,每次我使用它时,目标 View 的 viewDidLoad 都会被调用两次。 为什么会这样? Destination *myDestination = [self.storyboard
是否可以将 UIViewController 添加到 storyboard,当使用 instantiateViewControllerWithIdentifier 创建时将返回 中指定的大小 Stor
我有两个不同的入口点: let entryPoint: UITabBarController = mainStoryboard.instantiateViewControllerWithIdentif
我正在尝试以编程方式将 ViewController 推送到导航 Controller 中,并且我正在使用我的 Storyboard来创建它。 这是我的代码: + (void) pushViewCon
当我尝试在 iPhone 上 instantiateViewControllerWithIdentifier 时,应用程序崩溃了,尽管这在 ios 模拟器上运行良好。我使用的代码是: let ques
我有一个 Storyboard 并从如下代码实例化一个 View Controller : NSLog(@"1"); MyController *vc = (MyController *)[[UISt
我想创建一种通过自定义转换显示在主 Controller 中的弹出 View 。 我将弹出 View Controller 创建到 Storyboard中,并将其 View 设置为自由形式,然后调整
我经常发现在我的项目中我可能需要通过 Storyboard ID/Restoration ID 启动 UIViewController;但是,我经常通过查询包含与标题关联的 ID 的字典来获取 ID,
和有什么区别实例化ViewControllerWithIdentifier 和 initWithNibName ,除了前者来自 Storyboard ,后来不是吗? UIStoryboard *sig
我有一个 UIViewController (带有隐藏的 UINavigationController),其中包含一个 UIButton。单击该按钮会在另一个 UIViewController 上调用
我创建了一个使用大量容器 View 的应用程序。今天我发现 iOS 5 不支持嵌入式 segues(感谢 Xcode 让我知道。)所以现在我有很多嵌入式 segue,它们可以在彼此之间传递数据。 我正
如果我有一个 Storyboard,其 View Controller 已被标记。那么这两个 API 有什么区别呢? 我想知道返回的对象是否有一些差异。它们是完全相同的还是其中之一会初始化更多的东西?
我有一个问题: ExploreViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Profi
我正在尝试添加 View Controller 容器 library到remail电子邮件客户端。这个想法是 View Controller 容器在两层中呈现其 subview Controller
我有一个名为 ContentViewControllerPartial 的类,它扩展了 UIViewController。我使用实例化它几次content = [self.storyboard ins
我是一名优秀的程序员,十分优秀!