Best way to handle UITableViewCell
I have a table that has about 10 cells, 4 different types. I subclassed UITextViewCell because I wanted to have an IBOutlet for the label and a UITextField. Not sure if this is the best way to handle this, but it works so far. Then I had a cell for the floor, so I decided instead of subclassing UITableViewCell, I took my already subclassed cell with 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 awful is it for that? Should I subclass UITableViewCell 5 times for one complex tableView? Does it work in extreme cases, such as in the following order?
source to share
I would go for subclassing. Subclasses are cheap. The cells are of different types, and what you are doing now is iterating over all subzones and checking every kind of class membership - that's slow! The subclass will clean up your code and make it faster at the same time. Don't try to put too many things in one container.
source to share