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???


What mode to use to decrypt RSA message from iPhone in Java?

1:

What's this {{0,0},{w,h}} doing?
When you created your UIViewControllers you never released your own ownership of it, so until you release it yourself, it will never go away. Getting phone UUID through iPhone SDK The problem is this nothing else owns the UIViewControllers, so if you used autorelease, they would be deallocated right away.. Is there a way to use C++ for iPhone development? My quick fix would be to create an NSMutableArray and add them to the array before calling release on them. Getting the visible rect of an UIScrollView's content Then, when you want to release all of your UIViewControllers, remove them from the array. Getting first three digits from int/float NSMutableArray retains ownership of objects you add to it and releases ownership upon removal or deallocation. How can a C# programmer build software for iPhone? Something like this:. Saving reference to UITableViewCell
-(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 46 user ratings 176 reviews