how to release uiview added as subview in scrollview?


how to release uiview added as subview in scrollview?



i have added a UIViewController's view and a button to scrollview as subview...now how do i release all instance of UIViewController's...here is an attached imagealt text

in the view every uiview has a button over it for further navigation....

now i want to release uiview's and remove buttons from the scrollview ...here is my method to add subviews -(void)AddOneButton:(NSInteger)myButtonTag { lastButtonNumber = lastButtonNumber + 1;

if ((lastButtonNumber == 1) || ((lastButtonNumber%2) == 1)) { btnLeft = 8;} else if ((lastButtonNumber == 2) || ((lastButtonNumber%2) == 0)) { btnLeft = 162; }   CGRect frame1 = CGRectMake(btnLeft, btnTop, 150, 150); CGRect frame2 = CGRectMake(btnLeft, btnTop, 150, 150); UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom]; Button.frame = frame1; Button.tag = myButtonTag; [Button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; [Button setBackgroundColor:[UIColor clearColor]]; [Button setBackgroundImage:[UIImage imageNamed:@"WaitScreen.png"] forState:UIControlStateHighlighted]; [Button setBackgroundImage:[UIImage imageNamed:@"WaitScreen.png"] forState:UIControlStateSelected]; if(categoryType==1) { 	MultiChoiceThumbViewControllerobj = [[MultiChoiceThumbViewController alloc] initWithPageNumber:myButtonTag+1]; 	MultiChoiceThumbViewControllerobj.view.frame=frame2; 	MultiChoiceThumbViewControllerobj.lblCounter.text=[NSString stringWithFormat:@"%d of %d",myButtonTag+1,flashCardsId.count]; 	MultiChoiceThumbViewControllerobj.lblQuestion.text=[flashCardText objectAtIndex:myButtonTag]; 	[myScrollView addSubview:MultiChoiceThumbViewControllerobj.view];		 } [myScrollView addSubview:Button];  } 

with this code subviews count of scrollview is=96.

i have used this method in dealloc to remove subviews but it is not releasing UIvicontroller's

     for(UIView *subview in [myScrollView subviews]) 	{ 		[subview removeFromSuperview]; 		NSLog(@"Subviews Count=%d",myScrollView.subviews.count); 	} 

how do i release uiviewcontroller's???


How do I find out if I need to retain or assign an property?

1:

Can I use a mono library from Objective-C (on the iPhone)?
When you created your UIViewControllers you never released your own ownership of it, so until you release it yourself, it will never go away. Which are the Top Level Objects I need to create Outlests for in the File's Owner of my Nib, so that I have less memory problems? The problem is this nothing else owns the UIViewControllers, so if you used autorelease, they would be deallocated right away.. iPhone Data My quick fix would be to create an NSMutableArray and add them to the array before calling release on them. Why don't I have to release these objects? Then, when you want to release all of your UIViewControllers, remove them from the array. jQuery not loading on the iPhone NSMutableArray retains ownership of objects you add to it and releases ownership upon removal or deallocation. Asyncsocket VS NSstream Something like this:. NSOuputStream writing multiple times
-(id) init {     subViewControllers = [NSMutableArray new]; } ... -(void)AddOneButton:(NSInteger)myButtonTag {     ...     if(categoryType==1) {         MultiChoiceThumbViewControllerobj = [[MultiChoiceThumbViewController alloc] initWithPageNumber:myButtonTag+1];         MultiChoiceThumbViewControllerobj.view.frame=frame2;         MultiChoiceThumbViewControllerobj.lblCounter.text=[NSString stringWithFormat:@"%d of %d",myButtonTag+1,flashCardsId.count];         MultiChoiceThumbViewControllerobj.lblQuestion.text=[flashCardText objectAtIndex:myButtonTag];         [myScrollView addSubview:MultiChoiceThumbViewControllerobj.view];         [subViewControllers addObjet:MultiChoiceThumbViewControllerobj];         [MultiChoiceThumbViewControllerobj release];     }     [myScrollView addSubview:Button]; } ... - (void) removeSuperviews {     for(UIView *subview in [myScrollView subviews]) {             [subview removeFromSuperview];             NSLog(@"Subviews Count=%d",myScrollView.subviews.count);     }     [subViewControllers removeAllObjects]; } 


76 out of 100 based on 51 user ratings 326 reviews

*