2

在我的应用程序中,我有 custom UITableViewCell,并且UIStepperUILabel自定义单元格中有 and 。我不知道如何检查单击了哪个步进器。那么这是一种知道单击了哪个单元步进器的方法吗?

- (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;
}
4

2 回答 2

7

另一种选择是:

在 UIStepper 值更改时触发的方法中(例如上面的@max_),您可以执行以下操作:

- (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];
}
于 2012-03-18T19:39:35.923 回答
0
[step addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventValueChanged];

- (void) someAction:(UIStepper *) stepper {
    NSLog(@"stepper clicked");
}
于 2012-03-18T19:15:53.103 回答