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

  • 相关阅读:
    Vsftp的PASV mode(被动模式传送)和Port模式及 Linux下VsFTP配置全方案
    vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误的解决方法
    CentOS7.2部署FTP
    Apache与Nginx的优缺点比较
    MySQL存储引擎--MyISAM与InnoDB区别
    CentOS 7下搭建配置SVN服务器
    Remi 安装源
    tmpx75 I2C 温度传感器驱动程序添加
    QT 5.7.0 交叉编译记录
    am335x SGX 移植
  • 原文地址:https://www.cnblogs.com/hxwj/p/4895644.html
Copyright © 2011-2022 走看看