UITableView Extension: Click cell to close the keyboard, load different cells, and listen for changes in textfeild content,

Source: Internet
Author: User

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

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.