我正在开发iOS 4应用程序。
我有这个ViewController:
@interface BlogViewController : UIViewController
{
...
UIView* tabBar;
}
@property (nonatomic, retain) IBOutlet UIView* tabBar;
及其实施:
及其实施:
@implementation BlogViewController
@synthesize tabBar;
- (void) dealloc
{
...
[super dealloc];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.tabBar = nil;
}
我的问题是,如果我有IBOutlet
属性,是否有必要像这样声明UIView
?
@interface BlogViewController : UIViewController
{
...
UIView* tabBar;
}
如果我这样做,我是否需要在dealloc
上发布它?
- (void) dealloc
{
...
[tabBar release];
[super dealloc];
}
答案 0 :(得分:3)
顺序:不,你不需要声明实例变量,是的,你需要释放对象。您可以考虑使用自动引用计数来使内存管理方面正确。
答案 1 :(得分:1)
是的,您确实需要发布IBOutlet,如果您保留了它。
但是,IBOutlets由其nib文件拥有,因此通常的做法是使用assign
或weak
@property
代替retain
或strong
。在这种情况下,不需要释放它。
答案 2 :(得分:0)
如果您正在使用xcode 4+,那么在创建插座时,它本身会在dealloc和viewDidUnload中发布相同内容,因此无需再次执行此操作。