そのため、昨日は正常に動作していた一部のコードが正しく動作していないようです。メソッドにセレクターを追加して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 クラス内にあります。私は他の回答を見て、メソッドのシグネチャを同一にしましたが、それは役に立ちません。誰かが何が起こっているのか説明できれば、それは素晴らしいことです、ありがとう.