在哪里调用自定义方法? viewDidLoad、viewWillLoad
我正在从服务器加载一些信息。我创建了一个单独的方法来执行此操作。然后我调用 [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定没有实例化您的
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 aUIViewController
. This doesn't mean however thatinitWithNibName
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.