gpt4 book ai didi

iphone - IBOutlets 使用的内存是如何管理的?

转载 作者:行者123 更新时间:2023-12-03 20:28:42 28 4
gpt4 key购买 nike

我的大多数 View Controller 中有几个 socket ,我总是将它们与头文件中的属性链接起来,如下所示:

IBOutlet UIButton *homeButton;
@property (nonatomic, retain) IBOutlet UIButton *homeButton;

因为我假设内存由 NIB 处理,所以我应该在此处使用分配吗?

最佳答案

引自Resource Programming Guide :

Objects in the nib file are created with a retain count of 1 and then autoreleased. As it rebuilds the object hierarchy, however, UIKit reestablishes connections between the objects using the setValue:forKey: method, which uses the available setter method or retains the object by default if no setter method is available. If you define outlets for nib-file objects, you should always define a setter method (or declared property) for accessing that outlet. Setter methods for outlets should retain their values, and setter methods for outlets containing top-level objects must retain their values to prevent them from being deallocated. If you do not store the top-level objects in outlets, you must retain either the array returned by the loadNibNamed:owner:options: method or the objects inside the array to prevent those objects from being released prematurely.

在那里您可以找到有关如何从 nib 文件加载对象的更多详细信息,但简而言之 - 不,您必须使用 IBOutlet 的保留属性。

关于iphone - IBOutlets 使用的内存是如何管理的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818068/

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