我想浏览UITextfields,但我有一个问题,因为nextresponder总是为零,我无法理解为什么。因此导航不起作用。
我使用这种方法:
- (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;
}
这是我初始化单元格的方式:
- (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";
}
答案 0 :(得分:1)
我认为你应该通过:Responders
我注意到了另外一件事:How to navigate through textfields ? ......
<强> All "tabbable" UITextFields are on the same parent view.
强>
所以也检查一下。
希望它对你有所帮助。