Hi,
I'm trying to add a UISegmentedControl in my tableview. I have two sections in my tableview and I want the segmented control to be placed in the 2nd section. In my implementation, I override viewForHeaderInSection as follows.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 1)
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(10, 0,tableView.bounds.size.width, 10)] autorelease];
NSArray *segmentTextContent = [NSArray arrayWithObjects:NSLocalizedString(@"Singles", @""), NSLocalizedString(@"Everyone", @""),nil];
UISegmentedControl *segmentedControl = [[[UISegmentedControl alloc] initWithItems:segmentTextContent] autorelease];
segmentedControl.selectedSegmentIndex = 1;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, tableView.bounds.size.width+10, 20);
[segmentedControl addTarget:self action:@selector(loadTable:) forControlEvents:UIControlEventValueChanged];
[headerView addSubview:segmentedControl];
return headerView;
}
else
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(10, 0,tableView.bounds.size.width, 10)] autorelease];
return headerView;
}
}
My problem is that once I select a particular segment, it doesn't appear to be selected. i.e. it's not getting dark colored as expected. I have placed the segmented control in my navigation bar earlier and it colors the segment after selection as expected.
Any help would be highly appreciated. Thanks