So, some code that was working fine yesterday doesn't seem to be working correctly. I'm adding a selector in my cellForRowAtIndexPath:
method, but it always throws PAYPHProductTableViewCell valueChanged:]: unrecognized selector sent to instance 0x8d6a6c0
. Here's my code:
- (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;
}
}
And here's the selector:
- (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];
}
All this code is within my ViewController class. I've gone through other answers and have made the method signatures identical, but that isn't helping. If someone could explain what's going on, that would be great, thanks.