ios - change first responders in uitableviewcell textfield -
i developing app using storyboard. there custom class uitableviewcell (moneyentrytableviewcell) contains uitextfield. 
question: want move focus other text fields, added in other cells, press previous/next (<>) in keyboard.
in .h file
@interface moneyentrytableviewcell : uitableviewcell  @property (strong, nonatomic) iboutlet uilabel *lblmemname; @property (strong, nonatomic) iboutlet uitextfield *textamount; @property (strong, nonatomic) iboutlet uilabel *lblmemid; // hidden   @end   in .m file
@implementation moneyentrytableviewcell  @synthesize lblmemname,textamount; - (void)awakefromnib { }  - (void)setselected:(bool)selected animated:(bool)animated {     [super setselected:selected animated:animated]; }  @end   in controller, cellforrowatindexpath func...
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      moneyentrytableviewcell *cell = (moneyentrytableviewcell *)[tableview dequeuereusablecellwithidentifier:@"useramountcell"];     if (!cell)     {          cell = [[moneyentrytableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"useramountcell"] ;     }     cell.selectionstyle =uitableviewcellselectionstylenone;      uilabel     *lblname  = (uilabel *)    [cell lblmemname];     lblname.tag =100;     lblname.text = [[self.memberslist objectatindex:indexpath.row] objectatindex:0];      uilabel     *lblid  = (uilabel *)    [cell lblmemid];     lblid.tag =101;     lblid.text = [[self.memberslist objectatindex:indexpath.row] objectatindex:1];      uitextfield *txtfield = (uitextfield *)[cell textamount];     txtfield.tag = 200 + indexpath.row;     txtfield.placeholder = @"0.00";     txtfield.delegate = self;     [txtfield addtarget:self  action:@selector(textfielddidchange:) forcontrolevents:uicontroleventeditingchanged];     txtfield.inputaccessoryview = keyboarddonebuttonview;      return cell; }   this screen shot of app. in advance.
you can create references textfields want jump between. when set cell, grab reference textfield , set it. example, i'm assuming have nsmutablearray *textfieldarray declared.
// within cellforrowatindexpath self.textfield1 = (uitextfield*)[cell viewwithtag:100]; [self.textfield1.setdelegate:self];  if (![textfieldarray containsobject:self.textfield1]) {     [textfieldarray addobject:self.textfield1]; }   this way, when recognize "next" button pressed, jump next index in textfieldarray , make text field first responder. can either keep track of index first responder, or iterate through array find 1 active...
for (int = 0; < [textfieldarray count]; i++) {     if ([[textfieldarray objectatindex:i] isfirstresponder]) {         if (i == [textfieldarray count]-1) // last item in array - dismiss             [[textfieldarray objectatindex:i] resignfirstresponder];         else // go next item             [[textfieldarray objectatindex:i+1] becomefirstresponder];     } }      
Comments
Post a Comment