어제 제대로 작동하지 않은 일부 코드가 올바르게 작동하지 않는 것 같습니다. 내 cellForRowAtIndexPath:
메서드에서 선택기를 추가하고 있지만 항상 PAYPHProductTableViewCell valueChanged:]: unrecognized selector sent to instance 0x8d6a6c0
을 throw합니다.인스턴스로 보내지는 인식 할 수없는 선택기 (스테퍼)
- (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 클래스에 있습니다. 다른 답변을 통해 메소드 서명을 동일하게 만들었지 만 이는 도움이되지 못합니다. 누군가가 무슨 일이 일어 났는지 설명 할 수 있다면 좋을 것입니다. 고마워요.
스테퍼 대신 셀에 valueChanged :를 호출하고 있다는 오류 메시지가 표시됩니다. cell.stepper가 스테퍼 대신 셀을 재조정하지 않는 한 게시 한 코드가 어떻게되는지는 알 수 없습니다. 이상하게 들릴 수도 있지만 cell.stepper를 반환하여 반환되는 내용을 확인해야합니다. 예외 브레이크 포인트를 추가하여 오류의 원인이되는 행을 확인할 수도 있습니다. – rdelmar