在IBAction之前调用过viewDidLoad? [英] viewDidLoad called before an IBAction?

查看:75
本文介绍了在IBAction之前调用过viewDidLoad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Xcode项目中,我有一个按钮,可做两件事.

in my Xcode project I have a button, that does two things.

首先:调用IBAction 第二:转到另一个视图(搜索)

First: call an IBAction Second: go to another view (segue)

在链接到按钮的动作中,我将变量设置为YES(全局变量),但是在链接视图的viewDidLoad方法中,其仍然为NO.不过,它在viewDidAppear中为YES.我不知道为什么不首先采取行动.我可以改变吗?我宁愿使用viewDidLoad方法,因为它加载起来似乎更快.

In the action linked to the button I set a variable to YES (global var), but in the viewDidLoad method in the linked view, its still NO. Its YES in viewDidAppear though. I wonder why the action is not called first. Can I change that? I'd prefer to use the viewDidLoad method, since it seems to load quicker.

推荐答案

在执行分配给按钮的segue之前,可以使用prepareForSegue方法将任何数据传递到目标视图.此数据将在目标视图viewDidLoad

You can use the prepareForSegue method to pass whatever data to the destination view before the segue assigned to the button is performed. This data will be available in the destination view viewDidLoad

这篇关于在IBAction之前调用过viewDidLoad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆