我创建了一个视图并将视图分配给viewcontroller
UIView *newView=[[UIView alloc] initWithFrame:CGRectMake(0,0,320,460)];
在viewDidLoad方法中我已将视图分配给viewcontroller
-(void)viewDidLoad{
self.view=newView;
//[view release]; In this case also the application crashing
}
-(void)dealloc{
[newView release];//IN this case also the application crashing.
[super dealloc];
}
崩溃日志就是这样。
如何发布newView?否则viewcontroller本身将负责释放newView。
答案 0 :(得分:0)
在大多数情况下,您将执行以下操作:
- (void) loadView {
// Don't call super here if you assign the view property
UIView *newView = [[UIView alloc] initWithFrame: [UIScreen mainScreen].applicationFrame];
self.view = newView;
[newView release];
// the view is now owned and retained by the UIViewController
}
Apple建议您在-loadView
中分配视图,分配和发布视图,而不要在-dealloc
中担心。这在您的视图可能在低内存条件下被清除的情况下非常重要。