ios - Go to next UITextField in different UITableViewCells -
i have uitableview
x number of cells. in cells there x number uitextfields
. want next-button on keyboard highlight next textfield. got working in same cell not when it's supposed jump textfield in different cell. first textfield in each cell has tag 0 , second tag 1 , on. code:
- (bool)textfieldshouldreturn:(uitextfield *)textfield{ // fetch current cell uitableviewcell *cell = (uitableviewcell *)textfield.superview.superview; // tag next textfield nsinteger nexttag = textfield.tag + 1; uitextfield *nexttextfield; for(uitextfield *subview in cell.contentview.subviews){ if([subview iskindofclass:[uitextfield class]]){ if(subview.tag == nexttag){ nexttextfield = subview; break; } } } if(nexttextfield){ // go next textfield [nexttextfield becomefirstresponder]; } else{ // indexpath current cellen nsindexpath *indexpath = [travellerstableview indexpathforcell:cell]; uitableviewcell *nextcell; // while cell exist @ indexpath while([travellerstableview numberofsections] > indexpath.section+1){ nextcell = [self tableview:travellerstableview cellforrowatindexpath:[nsindexpath indexpathforrow:indexpath.row insection:indexpath.section+1]]; if(nextcell){ for(uitextfield *subview in nextcell.contentview.subviews){ if([subview iskindofclass:[uitextfield class]]){ if(subview.tag == 0){ nslog(@"%@", subview.placeholder); nexttextfield = subview; break; } } } // go next textfield or cell if(nexttextfield){ [nexttextfield becomefirstresponder]; nslog(@"next!"); break; } else{ indexpath = [nsindexpath indexpathforrow:indexpath.row insection:indexpath.section+1]; } } } if(!nexttextfield){ [textfield resignfirstresponder]; } } return no; }
the nslog
's behave expected. have different placeholders in textfields , next 1 echoed. next! echoed it's trying becomefirstresponder
.
i found issue. didn't fetch nextcell
tableview correctly. how should like:
nextcell = [travellerstableview cellforrowatindexpath:indexpath];
Comments
Post a Comment