UITableView Extension: Click cell to close the keyboard, load different cells, and listen for changes in textfeild content,
In fact, you only need one sentence to click cell to close the keyboard.
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {
[TableView endEditing: YES];
}
The content change of textfeild In the listener is to change the data in the array assigned to textfeild when the content of textfeild changes. The tag is used to mark different textfeild.
Newcell. textfeild. delegate = self;
Newcell. textfeild. tag = indexPath. row;
Newcell. textfeild. text = self. arrayWithCell3 [indexPath. row];
In the UITextFieldDelegate proxy method, the corresponding data is changed by tag
-(BOOL) textField :( UITextField *) textField shouldChangeCharactersInRange :( nsange) range replacementString :( NSString *) string {
Self. arrayWithCell3 [textField. tag] = [textField. text mutableCopy];
Return YES;
}
When loading different cells, you can register different cells for them.
Registration:
[_ Tableveiw registerClass: [CustomCell class] forCellReuseIdentifier: @ "cellID"];
[_ Tableveiw registerClass: [CustomCell1 class] forCellReuseIdentifier: @ "cellID1"];
[_ Tableveiw registerClass: [CustomCell2 class] forCellReuseIdentifier: @ "cellID2"];
Load:
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
UITableViewCell * cell = nil;
If (indexPath. section = 0 ){
Cell = [tableView dequeueReusableCellWithIdentifier: @ "cellID"];
CustomCell * newcell = (CustomCell *) cell;
Newcell. label. text = @" 00000 ";
} Else if (indexPath. section = 1 ){
Cell = [tableView dequeueReusableCellWithIdentifier: @ "cellID1"];
} Else {
Cell = [tableView dequeueReusableCellWithIdentifier: @ "cellID2"];
CustomCell2 * newcell = (CustomCell2 *) cell;
Newcell. textfeild. delegate = self;
Newcell. textfeild. tag = indexPath. row;
Newcell. textfeild. text = self. arrayWithCell3 [indexPath. row];
}
Cell. selectionStyle = UITableViewCellSelectionStyleNone;
Return cell;
}
Demo link: https://github.com/WuJiForFantasy/UITableViewCell.git