Reputation: 29870
I have a UITableView, but I would like the cells to look differently depending on the section. Specifically, I would like section 0 and one to have a UIStepper on the right side of the cell.
In IB, the UITableView has two prototype cells. In the first one, I added the UIStepper, and the second one I left as the default (blank). I gave the stepper UITableViewCell the identifier "StepperCell" (in IB), and the non-stepper cell the identifier "Cell".
Now, in cellForRowAtIndexPath
, I am checking the section number and then applying the appropriate reuse identifier like so:
static NSString *stepper = @"StepperCell";
static NSString *normal = @"Cell";
NSString *identifier = normal;
NSInteger section = [indexPath section];
if (section == 0 || section == 1)
{
identifier = stepper;
}
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier: identifier];
I thought that this might work as I intend it to, but it leaves all cells as the default, blank cell. Is there a way to do what I described, without programmatically adding a UIStepper?
edit - it looks like the UIStepper is not showing because the accessory view is set to None in IB. Is there a way to make the UIStepper my accessory view in IB, rather than the default choices (detail disclosure, etc)?
Upvotes: 3
Views: 4470
Reputation: 11542
I can add UIStepper to the prototype cell in my IB without any problem.
Make sure not to forget about setting Style
to Custom
in the "Attributes inspector" of the prototype cell in your IB.
Upvotes: 1