I have a table which has roughly 10 cells, 4 different types. I subclassed UITextViewCell because I wanted to have an IBOutlet to a label and to a UITextField. Not sure if that was the best way of handling it, but it works thus far. Next, I had a cell for gender, so I figured instead of subclassing UITableViewCell, I took my already subclassed cell with a UILabel and UITextField, and wrote the following code:
NSArray *buttonNames = [NSArray arrayWithObjects:@"Male", @"Female", nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
segmentedControl.momentary = YES;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(75, 5, 130, 30);
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
for (UIView *oneView in cell.contentView.subviews) {
if ([oneView isMemberOfClass:[UITextField class]]) {
[cell.contentView insertSubview:segmentedControl aboveSubview:oneView];
[oneView removeFromSuperview];
}
}
[segmentedControl release];
How horrible is that for going about this? Should I be subclassing UITableViewCell 5 times for one complex tableView? Is handling it in edge cases such as the following OK?