因此,昨天运行良好的某些代码似乎无法正常运行。我在我的cellForRowAtIndexPath:
方法中添加了一个选择器,但它总是抛出PAYPHProductTableViewCell valueChanged:]: unrecognized selector sent to instance 0x8d6a6c0
. 这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
//some code
}
else
{
NSString *cellIdentifier = @"PAYPHProductTableViewCell";
PAYPHProduct *product = self.myCart[indexPath.row - 1];
PAYPHProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[cell loadName:product.name Price:product.price Quantity:product.quantity];
[cell.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
return cell;
}
}
这是选择器:
- (IBAction)valueChanged:(UIStepper *)sender
{
int value = [sender value];
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
((PAYPHProduct *) self.myCart[indexPath.row - 1]).quantity = value;
[self updateNumItemsAndSubtotal];
[self.tableView reloadRowsAtIndexPaths:@[indexPath, [NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}
所有这些代码都在我的 ViewController 类中。我已经完成了其他答案,并使方法签名相同,但这无济于事。如果有人可以解释发生了什么,那就太好了,谢谢。