I'm building a segmented control within my viewDidLoad method, like so:
NSArray *tabitems = [NSArray arrayWithObjects:@"ONE", @"TWO", nil];
UISegmentedControl *tabs = [[UISegmentedControl alloc] initWithItems:tabitems];
tabs.segmentedControlStyle = UISegmentedControlStyleBar;
tabs.frame = CGRectMake(185.0, 7.0, 130.0, 30.0);
tabs.selectedSegmentIndex = 0;
[self.navigationController.navigationBar addSubview:tabs];
[tabs release];
But when the user goes Back in the uinavigationcontroller hierarchy, the segmented controller stays on the navigation bar. How would I get rid of it? Or am I doing something fundamentally wrong?
EDIT
Following Alex's suggestions, I propertized tabs and tried:
NSArray *tabItems = [NSArray arrayWithObjects:@"FAQs", @"Terms", nil];
self.tabs = [[UISegmentedControl alloc] initWithItems:tabItems];
but I'm not sure it's a good idea to alloc a property;
And I'm using
[self.tabs removeFromSuperview];
in my viewWillDisappear. Is that enough?