在哪里调用自定义方法? viewDidLoad、viewWillLoad

发布于 2024-08-24 09:57:23 字数 203 浏览 4 评论 0原文

我正在从服务器加载一些信息。我创建了一个单独的方法来执行此操作。然后我调用 [self myCustomMethod] 来运行该方法。无论我在哪里调用 [self myCustomMethod] (initWithNibName, viewDidLoad, viewWillLoad, viewWillAppear, viewDidAppear),自定义方法都会被调用两次 - 这是怎么回事?

I am loading some info from a server. I have created a separate method to do this. I am then calling [self myCustomMethod] to run the method. No matter where I call [self myCustomMethod] (initWithNibName, viewDidLoad, viewWillLoad, viewWillAppear, viewDidAppear), the custom method is getting called twice - what's the deal?

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

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

发布评论

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

评论(1

生生漫 2024-08-31 09:57:23

您确定没有实例化您的 UIViewController 两次吗?或者在某个时候自己调用这些方法中的任何一个? initWithNibName 只会被调用一次,其他方法在 UIViewController 的生命周期中可能会被多次调用。但这并不意味着 initWithNibName 是调用您的方法的最佳位置。这取决于它具体做什么,例如,它是否需要对视图执行任何操作。

Are you sure you aren't instantiating your UIViewController twice? Or call any of these methods yourself at some point? initWithNibName will only be called once, the other methods may be called more than once in the life span of a UIViewController. This doesn't mean however that initWithNibName is the best place to call your method. It depends on exactly what it does, for example, wether it needs to do anything with the view.

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