如何在开始启动应用程序时加载所有控制器(xcode)?

发布于 2024-12-03 13:14:44 字数 466 浏览 2 评论 0原文

问题是,当我做某事时,例如在我未打开的不同控制器上向 UITextField 输入 @“Hallo” 代码,该 UITextField 仍然为空,但如果我之前已经打开过它,则 UITextField 将变为“Hallo

” 就会像这样的程序

+(void)MakeController2LblTextIsLikeMyStringAtController1{
         Controller2.lblText.text=MyString;
}

如果我在调用此方法之前从未加载过 Controller2, 。 Controller2.lblText.text 仍然为 null,但如果我还没有加载 Controller2,lblText.text 将 isEqual MyString。

问题是,如果我有 20-50 个不同的控制器,如何才能在启动应用程序时加载所有控制器?如何强制打开视图控制器以编程方式加载?

The problem is, when I do something, such as input @"Hallo" with code to UITextField at different Controller that I havent opened, that UITextField is still null, but if I already opened it before, the UITextField will become "Hallo"

the program like this

+(void)MakeController2LblTextIsLikeMyStringAtController1{
         Controller2.lblText.text=MyString;
}

if I never loaded Controller2 before I call this method. Controller2.lblText.text is still null, but If I havent loaded Controller2, lblText.text will isEqual MyString.

the problem is, If I have 20-50 different Controller, how can I make all of it load at start launch application? How to force open a view controller to load programatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老旧海报 2024-12-10 13:14:44

不要在启动时加载所有视图控制器。如果你尝试的话,操作系统很快就会因为内存使用而将你踢出局。相反,请考虑正确实施 MVC 范例。您需要在另一个视图控制器中访问 UILabel 表明您的应用程序的结构不太正确。

Don't load all your view controllers at launch. The OS will kick you out due to memory usage quickly if you try. Instead, look at implementing the MVC paradigm properly. Your need to access an UILabel in another view controller suggest your app's structure is not quite right.

依 靠 2024-12-10 13:14:44

抱歉,您认为如何将一些文本分配给甚至不存在的 UITextField 呢?当您分配和初始化控制器(任何类)时,它的属性也会被创建(初始化),因此您可以访问它们。您必须记住这一点,没有办法访问不存在的东西或其属性。
为什么一旦加载([alloc init])Controller2就可以访问它们可能是因为您没有释放它们。就这么简单。
如果你想在启动时加载所有这些,你可以有一个所有控制器类的数组,让 foreach 循环遍历它并一一地 [alloc init] 它们。但由于我不完全知道您的应用程序的用途,建议的方法可能与您的情况无关。这只是做你想做的事情的一种方式。

I'm sorry, but how do you think you can assign some text to a UITextField which does not even exist? When you alloc and init a controller (any class) its properties are also created (initialized), thus you can access them. You have to bear this in mind that there's no way to access to something or its properties that does not exist.
And why you can acess them once you load ([alloc init]) the Controller2 is probably because you do not deallocate them. That's as simple as this.
If you want to load all of them at startup you can have an array of all the Controller classes and let the foreach loop iterate through it and [alloc init] them one by one. But as I do not exacly know what your application is meant to do the suggested method might be irrelevant in your situation. That's just a way of doing what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文