【发布时间】:2012-03-09 17:29:37
【问题描述】:
在 iOS5 中使用 ARC 时,我对在视图中创建的子视图的引用是否应该使用 weak 或 strong 关键字声明感到困惑。
这是我的头文件的示例:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@class SCLGridView;
@interface MyViewController : UIViewController <UIPopoverControllerDelegate, MFMailComposeViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UIView *hiddenBrowserView;
@property (strong, nonatomic) SCLGridView *gridView;
@property (strong, nonatomic) UIImageView *backgroundView;
@property (strong, nonatomic) UIView *backgroundShadowView;
@property (strong, nonatomic) UIPopoverController* popOverController;
@end
我的印象是,我正在创建并想要引用的视图应该使用 strong 关键字声明,因为我拥有这些视图(我创建它们)。但是,我已将 hiddenBrowserView 声明为弱,因为我正在引用我在情节提要中创建的视图。这种方法是否正确,或者我应该将所有这些视图引用设为弱,即使是对我以编程方式创建的视图的引用?谢谢!
【问题讨论】:
标签: ios memory-management automatic-ref-counting