2

In my app I have custom UITableViewCell, and I have UIStepper and UILabel in the custom cell. I don't know how to check which stepper was clicked. So is it a way to know from which cell stepper was clicked?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    NSString *CellIdentifier = @"Cell";
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        if ([nib count] > 0) {
            cell = self.tbcell;
        }
    }
    return cell;
}
jszumski
  • 7,430
  • 11
  • 40
  • 53
Dmitriy Kalachniuk
  • 372
  • 1
  • 6
  • 25
  • UITableViewCell *cell; NSString *CellIdentifier = @"Cell"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; if ([nib count] > 0) { cell = self.tbcell; } } return cell; – Dmitriy Kalachniuk Mar 18 '12 at 19:32

2 Answers2

7

An alternative is:

In the method that gets fired when the UIStepper value changes (e.g. @max_, above), you can do the following:

- (IBAction)stepperValueDidChanged:(UIStepper *)sender {
    UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
    // assuming your view controller is a subclass of UITableViewController, for example.
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
}
Sierra Alpha
  • 3,707
  • 4
  • 23
  • 36
0
[step addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventValueChanged];

- (void) someAction:(UIStepper *) stepper {
    NSLog(@"stepper clicked");
}
max_
  • 24,076
  • 39
  • 122
  • 211