gpt4 book ai didi

objective-c - 为什么在处理子类的成员之前调用父类(super class)的 viewDidUnload?

转载 作者:行者123 更新时间:2023-12-04 06:30:31 25 4
gpt4 key购买 nike

我在其中一个 Apple 示例中看到了此代码:

- (void)viewDidLoad {

[super viewDidLoad];
// Set the content size for the popover: there are just two rows in the table view, so set to rowHeight*2.
self.contentSizeForViewInPopover = CGSizeMake(310.0, self.tableView.rowHeight*2.0);
}

-(void) viewDidUnload {
[super viewDidUnload];

self.splitViewController = nil;
self.rootPopoverButtonItem = nil;
}

我来自 C++ 背景,所以(我认为),我习惯于在调用基类的 unload 方法之前看到派生类的成员被处理。在这种情况下预先调用 super viewDidUnload 的原因是什么,或者只是任意的?

最佳答案

我认为在这种情况下这并不重要。您只会减少对免费 iboutlets 或您在 viewDidLoad 中创建的其他内容的引用计数。基本上,这只是基类中 viewDidUnload 代码的扩展,而不是覆盖或析构函数调用。

通常,当您希望在子类中执行方法时也执行基类代码时,您首先调用 super 方法,除非有充分的理由不这样做。

关于objective-c - 为什么在处理子类的成员之前调用父类(super class)的 viewDidUnload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5479147/

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