首页 > 其他 > 详细

UITableView延伸:点击cell关闭键盘,加载不同cell,监听里面的textfeild内容改变

时间:2015-10-20 19:28:21      阅读:284      评论:0      收藏:0      [点我收藏+]

其实点击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

 

 

 

UITableView延伸:点击cell关闭键盘,加载不同cell,监听里面的textfeild内容改变

原文:http://www.cnblogs.com/hxwj/p/4895644.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!