目标C 基本问题
我使用基于视图的模板制作了一个简单的应用程序。我仅将 nslog 放入 viewController 文件中的视图 didload 方法中,并将 nslog 放入 applicationDidFinishLaunch 方法(在 appDelegate 中)中,以检查首先调用哪个类文件。
运行后我得到: viewController 首先运行,然后是 appdelegate ..但我认为 appdelegate 应该首先然后根据需要调用其他...请给我适当的理由。
注意到 --i 没有在我的 appDelegate(inside application didFinishLaunch) 中调用 viewController (没有创建对象)。我正在使用ios4
i made a simple application using view based template.and i put only nslog inside view didload method in viewController file and also inside applicationDidFinishLaunch method (in appDelegate )to checked which class file called first.
after the run i got: viewController Run first and then appdelegate ..but i think appdelegate should first then other's called according to the need ... plz give me the proper reasion.
Noted that --i did not call viewController (didnot make object) in my appDelegate(inside application didFinishLaunch) . i am using ios4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的视图控制器是 AppDelegate 的属性,类似于代码引用
,那么它可能在分配时由 AppDelegate 分配。根据Apple文档,viewDidLoad是在视图加载到内存后运行的,这可能有点令人困惑,因为该语言可以让你相信它是在它加载到屏幕上时运行的。
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW25
移动您的 NSLog 语句 viewDidAppear 以获得您期望的结果。以下是两个示例片段,其中包含您期望语句加载的方式。
ViewController.m
AppDelegate_Shared.m
If your View Controller is a property of the AppDelegate, similar to the code reference
then it is probably getting allocated by the AppDelegate when it is being allocated. According to the Apple documentation viewDidLoad is run after the view is loaded into memory, which can be a little confusing, since the language can make you believe it's when it's loaded onto the screen.
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW25
Move your NSLog statement to viewDidAppear for the result you were expecting. Here's two sample snippets with the way you should expect the statements to load.
ViewController.m
AppDelegate_Shared.m
如果初始视图尚未加载,则显然应用程序尚未完成启动。
消息按正确的顺序发送。
If the initial view hasn't loaded then clearly the application has not finished launching.
The messages are sent in the right order.