gpt4 book ai didi

ios - UIViewController 生命周期

转载 作者:行者123 更新时间:2023-11-29 12:46:18 26 4
gpt4 key购买 nike

结果:

2014-05-12 11:17:24.891 viewController[2206:60b] init

2014-05-12 11:17:24.910 viewController[2206:60b] loadView

2014-05-12 11:17:24.911 viewController[2206:60b] viewDidLoad!

2014-05-12 11:17:24.912 viewController[2206:60b] viewWillAppear

2014-05-12 11:17:24.916 viewController[2206:60b] dealloc

2014-05-12 11:17:24.982 viewController[2206:60b] viewDidAppear

为什么在viewWillAppear方法和viewDidAppear方法之间dealloc方法?

 - (id)init
{
if (self = [super init]) {

NSLog(@"init");
}
return self;
}

- (void)loadView
{
NSLog(@"loadView");
[super loadView];
}

- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"viewDidLoad!");
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"viewWillAppear");
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"viewDidAppear");
}

- (void)dealloc
{
NSLog(@"dealloc");
[super dealloc];
}

最佳答案

来自您的评论:

The method dealloc log self address was changed! – user3349116

您正在查看来自 View Controller 的不同实例的日志。当您尝试跟踪此类事件时,请在您的日志中包含 self。并确保在执行此操作时不要破坏 View Controller (您的 loadView 实现可能意味着您没有任何内容可显示在屏幕上)。

无论如何, View Controller 生命周期都有详细的文档记录,而且在大多数情况下非常明显。

关于ios - UIViewController 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23600612/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com