matt matt - 4 months ago 14
iOS Question

how to release the Views?

i create views in viewDidLoad,such as

UIScrollView* scrollViewright = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)];
[scrollViewright setContentSize:CGSizeMake(400,1000)];
[self.view addSubview:scrollViewright];


so,how can i release them?

i use [scrollViewright release]; in '- (void)dealloc' and self.scrollViewright = nil in '-(void)viewDidUnload',both of them tell me wrong ,so can anybody help me?

Answer

Well you have two kinds of release that can be done:

UIScrollView* scrollViewright = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)];
[scrollViewright setContentSize:CGSizeMake(400,1000)];
[self.view addSubview:scrollViewright];
[scrollViewright release];

And the next one, when you want to remove the scrollView from the main view:

[scrollViewright removeFromSuperview];