I’m making an app with a UITableView that uses ELCTextfieldCells. For some cells I set a UISegmentedControl on top of it and disable UITextField. “A picture is worth a thousand words”, so here’s the screenshot of what I get when I slide to that UITableView:

And after moving that cell from the screen and putting it back(basically reloading) I get the following:

So there are 2 problems:
- UISegmentedControl is not visible when the view appears for the first time;
- The values of that UISegmentedControl are written in the cell somewhere on top;
Some code that anyhow affects these cells:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[self.tableViewCellValues objectAtIndex:indexPath.row]rangeOfString:@"Gender"].location != NSNotFound || [[self.tableViewCellValues objectAtIndex:indexPath.row]rangeOfString:@"Still Active Employee"].location != NSNotFound) {
static NSString *CellIdentifier = @"CellWithSegmentedControl";
ELCTextfieldCell *cell = (ELCTextfieldCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ELCTextfieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[self configureCell:cell atIndexPath:indexPath];
UISegmentedControl *segmentedControl;
if ([cell.leftLabel.text rangeOfString:@"Gender"].location != NSNotFound) {
segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Male", @"Female", nil]];
} else {
segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Yes", @"No", nil]];
}
segmentedControl.frame = CGRectMake(215, 6, cell.rightTextField.frame.size.width, cell.rightTextField.frame.size.height - 10);
segmentedControl.tag = 26;
[segmentedControl addTarget:self action:@selector(segmentedControlHasChangedValue:) forControlEvents:UIControlEventValueChanged];
UIFont *font = [UIFont boldSystemFontOfSize:12.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont];
[segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
[cell addSubview:segmentedControl];
[cell bringSubviewToFront:segmentedControl];
cell.rightTextField.text = @"";
cell.rightTextField.enabled = NO;
return cell;
}
//checks and other stuff for other cells
}
-(void)segmentedControlHasChangedValue:(id)sender {
NSLog(@"Nothing implemented here yet");
}
Any help on how can I fix it would be greatly appreciated.
Thank you
you are giving
cell.rightTextField.frame.size.height - 10may be thats why it is going up, have you checked the height ?