-1

I want to navigate through UITextfields, but I have a problem, because nextresponder is always nil and I can't understand why. Because of that the navigation doesn't work.

I use this method:

  - (BOOL)textFieldShouldReturn:(UITextField*)textField {

UITableViewCell * curentCell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath * indexPath = [tableView indexPathForCell:curentCell];

NSInteger nextTag;
if (indexPath.row == 3)
    nextTag = textField.tag + 3;
else if (indexPath.row == 6)
    nextTag = textField.tag + 1;
else if (indexPath.row == 7)
    nextTag = textField.tag + 1;
else if (indexPath.row == 8)
    nextTag = textField.tag + 2;

UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];

if (nextResponder) {
    [nextResponder becomeFirstResponder];
} else {
    [textField resignFirstResponder];
}

[self deleteBarButton];

tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

return NO;
}

Here is the way I initialize the cells:

- (void) initCells
{
NSArray *topLevelObjectsProdus = [[NSBundle mainBundle] loadNibNamed:@"CellProdusAsigurareHeader" owner:self options:nil];
cellHeader = [topLevelObjectsProdus objectAtIndex:0];
UIImageView * img = (UIImageView *)[cellHeader viewWithTag:1];
img.image = [UIImage imageNamed:@"calculator-casco.png"];

NSArray *topLevelObjectsMarca = [[NSBundle mainBundle] loadNibNamed:@"CellAutovehicul" owner:self options:nil];
cellMasina = [topLevelObjectsMarca objectAtIndex:0];
UILabel * lblCell = (UILabel *)[cellMasina viewWithTag:2];
UIImageView * imgBgAuto = (UIImageView *)[cellMasina viewWithTag:5];
imgBgAuto.image =[UIImage imageNamed:@"alege-masina-portocaliu.png"];

lblCell.textColor = [YTOUtils colorFromHexString:ColorTitlu];
lblCell.text = @"Alege masina";

NSArray *topLevelObjectsProprietar = [[NSBundle mainBundle] loadNibNamed:@"CellPersoana" owner:self options:nil];
cellProprietar = [topLevelObjectsProprietar objectAtIndex:0];
UIImageView * imgBgProprietar = (UIImageView *)[cellProprietar viewWithTag:5];
imgBgProprietar.image =[UIImage imageNamed:@"alege-masina-portocaliu.png"];
UILabel * lblCellP = (UILabel *)[cellProprietar viewWithTag:2];
lblCellP.textColor = [YTOUtils colorFromHexString:ColorTitlu];
lblCellP.text = @"Alege proprietar";

NSArray *topLevelObjectsnrKm = [[NSBundle mainBundle] loadNibNamed:@"CellView_Numeric" owner:self options:nil];
cellNrKm = [topLevelObjectsnrKm objectAtIndex:0];
txtNumarKm = (UITextField *)[cellNrKm viewWithTag:2];
[(UILabel *)[cellNrKm viewWithTag:1] setText:@"Numar kilometri autovehicul"];
[(UITextField *)[cellNrKm viewWithTag:2] setKeyboardType:UIKeyboardTypeNumberPad];
[YTOUtils setCellFormularStyle:cellNrKm];

NSArray *topLevelObjectsCuloare = [[NSBundle mainBundle] loadNibNamed:@"CellView_String" owner:self options:nil];
cellCuloare = [topLevelObjectsCuloare objectAtIndex:0];
txtCuloare = (UITextField *)[cellCuloare viewWithTag:2];
[(UILabel *)[cellCuloare viewWithTag:1] setText:@"Culoare autovehicul"];
[YTOUtils setCellFormularStyle:cellCuloare];

NSArray *topLevelObjectscalc = [[NSBundle mainBundle] loadNibNamed:@"CellCalculeaza" owner:self options:nil];
cellCalculeaza = [topLevelObjectscalc objectAtIndex:0];
UIImageView * imgBgCalculeaza = (UIImageView *)[cellCalculeaza viewWithTag:1];
imgBgCalculeaza.image =[UIImage imageNamed:@"calculeaza-casco.png"];
UILabel * lblCellC = (UILabel *)[cellCalculeaza viewWithTag:2];
lblCellC.textColor = [YTOUtils colorFromHexString:ColorTitlu];
lblCellC.text = @"Cere oferta";
 }
Maria Stoica
  • 211
  • 2
  • 13

1 Answers1

1

I think you should go through : Responders

I noticed one more thing from : How to navigate through textfields ? that ...

All "tabbable" UITextFields are on the same parent view.

So check for that also.

Hope it will be helpful to you.

Community
  • 1
  • 1
Bhavin
  • 27,155
  • 11
  • 55
  • 94