zoukankan      html  css  js  c++  java
  • UITableView延伸:点击cell关闭键盘,加载不同cell,监听里面的textfeild内容改变

    其实点击cell关闭键盘只要一句话

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView endEditing:YES];
    }

     监听里面的textfeild内容改变其实就是当textfeild内容改变的时候将赋值给他的数组的数据改变下就行了,用tag标示不同的textfeild

            newcell.textfeild.delegate = self;
            newcell.textfeild.tag = indexPath.row;
            newcell.textfeild.text = self.arrayWithCell3[indexPath.row];

     在UITextFieldDelegate代理方法中通过tag改变相应的数据

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        self.arrayWithCell3[textField.tag] = [textField.text mutableCopy];
        return YES;
    }

     加载不同的cell就是给他注册不同的cell,取的时候也那样取就行了

    注册:

        [_tableveiw registerClass:[CustomCell class] forCellReuseIdentifier:@"cellID"];
        [_tableveiw registerClass:[CustomCell1 class] forCellReuseIdentifier:@"cellID1"];
        [_tableveiw registerClass:[CustomCell2 class] forCellReuseIdentifier:@"cellID2"];

     加载:

    -(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链接:https://github.com/WuJiForFantasy/UITableViewCell.git

  • 相关阅读:
    统一建模语言UML轻松入门之综合实例
    统一建模语言UML轻松入门之动态建模
    LINQ体验(3)——C# 3.0新语言特性和改进(下篇) 【转】
    Visual Studio 2008新特性【转】
    vs2008 新特性【转】
    LINQ体验(1)——C# 3.0新语言特性和改进(上篇) 【转】
    C# 3.0 的Lambda表达式(Lambda Expressions)【转】
    LINQ体验(2)——C# 3.0新语言特性和改进(上篇) 【转】
    结构体计算结构体字节大小以及字节对齐
    web.config 中SessionState的配置
  • 原文地址:https://www.cnblogs.com/hxwj/p/4895644.html
Copyright © 2011-2022 走看看