Hi guyss, i have a view that addes a subview programmtically
SelectionScreenTable *aSelectionScreenTableViewController = [[SelectionScreenTable alloc] initWithNibName:@"SelectionScreenTable" bundle:[NSBundle mainBundle]];
aSelectionScreenTableViewController.view.bounds = CGRectMake(0,0,955,520);
aSelectionScreenTableViewController.view.center = CGPointMake(528, 379);
[self.view addSubview:aSelectionScreenTableViewController.view];
Now i wish to remove it on clicked on a button and add it again so i did it wrote another 1 like this
SelectionScreenTable *viewController =[[SelectionScreenTable alloc]initWithNibName:@"SelectionScreenTable" bundle:nil];
viewController.view.bounds = CGRectMake(0,0,955,520);
viewController.view.center = CGPointMake(528, 379);
UIView *CV = [UIView alloc];
CV = [[self.view subviews]objectAtIndex:3];
[CV removeFromSuperview];
[CV release];
[self.view addSubview:viewController.view];
it Works but one thing i noticed was when it was removed and added on again. the
[self.view subviews]objectAtIndex:3 seems to change indexes? Because i can only click a certain number of times before the app crashes.
If so, should i do a increment where a variable + 1 everytime the button is clicked and use objectAtIndex:variable?