0

how do I add a UIStepper to every cell of my UITableView programmatically?

Thanks

Luca

luca
  • 36,606
  • 27
  • 86
  • 125

1 Answers1

2

One way to do it is to add the UIStepper to each cell as a subview in tableView:cellForRowIndexAtPath in your TableViewController. For example:

- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString* CellIdentifier = @"Cell";

   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
   {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

       UIStepper* stepper = [[UIStepper alloc] init];
       stepper.frame = CGRectMake(220, 10, 100, 10);
       [cell.contentView addSubview: stepper];
   }  

   return cell; 
}

This will add a stepper to the right-hand side of each cell in your table.

Marty
  • 7,464
  • 1
  • 31
  • 52