ios - Get indexPath for the customtableview textfield -
i have textfield in mycustomcell
, , set textfield delegate in cellforrowindexpath
tableview delegate. when user changes textfield value , calls textfieldshouldendediting
. works.
however, wonder how know textfield (indexpath) changed?
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; mycustomcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { // use if created cell ib cell = [[[nsbundle mainbundle] loadnibnamed:@"mycustomcell" owner:self options:nil] objectatindex:0]; // otherwise use cell = [[[mycustomcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; // set view controller text field delegate cell.textfield.delegate = self; } // configure cell... return cell; } - (bool)textfieldshouldendediting:(uitextfield *)textfield { [textfield resignfirstresponder]; return yes; }
set uitextfield
tag in cellforrowatindexpath
method. if there 1 section in tableview can set row tag. this.
cell.textfield.delegate = self; cell.textfield.tag = indexpath.row;
and in textfieldshouldendediting
method can check tag.
- (bool)textfieldshouldendediting:(uitextfield *)textfield { int row = textfield.tag; [textfield resignfirstresponder]; return yes; }
Comments
Post a Comment