Adding a UISegmentedControl to UITableView

Viewed 8519

How do I add a UISegmentedControl to a UITableView? Similar to the image found here: http://cdn.imore.com/sites/imore.com/files/styles/large/public/field/image/2012/08/iHomework-for-iPhone-managing-assignments-and-tasks.jpg

I would like to have a UISegmentedControl that sticks underneath the navigation bar.

This is what I've tried so far:

In my viewDidLoad method, I've created a UISegmentedControl

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"One", @"Two", nil]];
segmentedControl.frame = CGRectMake(50, 0, 220, 100);
[segmentedControl addTarget:self action:@selector(segmentedControlHasChangedValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];

However, the segmented control overlaps with the tableview itself.

EDIT

Additionally,I would like to create this uisegmentedcontrol fully programmatically as I don't want to use a nib file.

1 Answers
Related