Reputation: 319
I have searched through the net and still have no clue how to do this.
Basically I want to put a segment control bar with 3 buttons BELOW the navigation bar. When the user click the buttons in the segment control, it will cycle though a table view, a calendar and grid view.
I want to seperate those three views with three view controller classes..
I have already written the UITableViewController class and it can be shown normally without the segment control bar. But I still can't figure out how to add the segment control bar below the navigation bar.
I have read some of the tutorial such as http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited
however the segment control in this case is put inside the navigation bar but not below.
Anyone can help me? Thanks
Upvotes: 0
Views: 2133
Reputation: 7440
Try the following code:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Male", @"Female", nil]];
segmentedControl.frame = CGRectMake(50, 0, 220, 100);
[segmentedControl addTarget:self action:@selector(segmentedControlHasChangedValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];
Hope it helps
Upvotes: 1
Reputation: 1027
So you want the segmented control to be below the navigation bar, but above (and separate from) the table view controller? If this is the case, I would suggest going with Brian Palma's comment. Set up your view in interface builder, where you can add a table view and then resize it to leave room for the segmented control. Then add the segmented control and hook up your IBOutlets. You should end up with something like this:
You could do all of this programmatically as well, but interface builder will be much quicker.
Upvotes: 3