我有一个名为SettingsViewController的视图控制器和一个名为ViewAccounts的自定义UIView子类。在SettingsViewController中,我使用下面的代码将ViewAccounts视图添加到SettingsViewController中。未调用UIView子类的Dealloc方法
if(!self.viewAccounts)
{
ViewAccounts *objViewAccounts= [[ViewAccounts alloc] initWithFrame:CGRectMake(0, yViews, 320, 400) withViewController:self];
[self.view insertSubview:objViewAccounts atIndex:0];
self.viewAccounts = objViewAccounts;
[objViewAccounts release];
}
问题是ViewAccounts(UIView的子类)的dealloc方法没有被调用。如果我注释这两行代码,则会调用dealloc方法。
[self.view insertSubview:objViewAccounts atIndex:0];
self.viewAccounts = objViewAccounts;
我想这个问题是有保留计数,它得到由1当我们使用insertSubview或addSubiew增加,但如何摆脱它。这是使用它的正确方法吗?
非常感谢您提供了很好的信息。自从我使用assign之后,应用程序正在退出。现在它工作正常。只是为了确保,如果我们保留一个属性,在dealloc方法中,应该使用self.anyProperty = nil还是仅仅是[anyProperty release]或者两者兼而有之? – iHS 2011-03-26 00:11:50