Hi!
I am currently adding a UISegmentedcontrol to the toolbar in the navigation controller programactically (As below).
This approach works fine, I have my UISegmentedcontrol, it fires the selector that I have setup no problems.
Problem is - I would like to use the selectedIndex of this control in order to query my data model and present a different view of data for each 'segment' - but I am having trouble getting the selectedIndex.
In my travels I have been consulting the 'Top Songs' example code provided by Apple. In this code they build up their interface via UISegmentedControl object in the viewController and IB. In doing so they can access the UISegmentedControl selectedIndex. I am adding mine programmactically and do not have this freedom.
'SHOULD' I have a UISegmentedControl defined in my viewController? If so, if I want to continue building my menu programmactically, how do I go about accessing the information from the control buried within the navigationcontrol uitoolbar?
I'm clearly missing something basic. Any assistance is always greatly appreciated :)
"[self.navigationController setToolbarHidden:NO];
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
NSArray *tabitems = [NSArray arrayWithObjects:@"ONE", @"TWO", @"THREE", @"FOUR", nil]; UISegmentedControl *tabs = [[UISegmentedControl alloc] initWithItems:tabitems];
[tabs addTarget:self action:@selector(pickedSegment:) forControlEvents:UIControlEventValueChanged];
tabs.segmentedControlStyle = UISegmentedControlStyleBar; tabs.frame = CGRectMake(60, 8, 180, 30); tabs.selectedSegmentIndex = 0; //[self.navigationController.navigationBar addSubview:tabs]; [self.navigationController.toolbar addSubview:tabs]; [tabs release];"