gpt4 book ai didi

ios - 有必要在viewWillAppear中调用super吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:19 26 4
gpt4 key购买 nike

我试图了解调用 View 的方法调用是否/将出现和消失的场景。

我所做的是选择表格单元格(灰色突出显示),转到详细 View 并返回并取消选择所选行(删除所选单元格的灰色)。

这是我的方法:

-(void)viewDidAppear:(BOOL)animated {
DLog(@"%@ did appear", self);
[super viewDidAppear:animated];

if (_isPushed) {
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
_isPushed=NO;
}
}

-(void)viewWillAppear:(BOOL)animated {
DLog(@"%@ will appear", self);
[super viewWillAppear:animated]; //If I remove this super call , then it works fine and there is no delay in deselecting the table cell
}

-(void)viewWillDisappear:(BOOL)animated {
DLog(@"%@ will disappear", self);
[super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
_isPushed=YES;
}

所以,当我放置断点时,流程是这样的:

没有 super 调用:

在推送到新 VC 时:

current viewWillDisappear    //makes sense
new viewWillAppear //makes sense
current viewDidAppear // doesnt make sense , y this should get called as the view is already appeared?
current viewWillDisappear // make sense
current viewDidDisappear //make sense
new viewDidAppear //make sense

从推送的 VC 回来时:

current viewWillDisappear
new viewDidDisappear
current viewDidDisappear
new viewDidAppear

super 调用:

在推送到新 VC 时:

current viewWillDisappear
new viewWillAppear
current viewDidAppear
current viewWillDisappear
current viewDidDisappear
new viewDidAppear

从推送的 VC 返回时:

current viewWillDisappear
new viewDidDisappear
current viewDidDisappear
new viewDidAppear

无论我是否使用 super 调用,流程都几乎相同。但我面临的问题是,当我在 viewWillAppear 中使用 super 调用时,取消选择单元格会有延迟(大约 >1 秒)。

如果我不在 viewWillAppear 中使用 super 调用,则没有延迟并且单元格正在取消选择(大约 <0.5 秒)

我不确定是否使用 super call。

谁能告诉我为什么取消选择单元格会出现延迟?

最佳答案

是的,documentation声明你必须:

Discussion

This method is called before the receiver's view is about to be added to a view hierarchy and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with displaying the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. If you override this method, you must call super at some point in your implementation.

关于ios - 有必要在viewWillAppear中调用super吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32594025/

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