好久不用代码实现自定义UItableViewCell

本文探讨了iOS开发中用户输入信息可能因滑动而丢失的问题,并提出了三种解决方案:不复用cell、使用UITextField代理和利用代理存储已输入信息。

类似这样需要用户输入的时候要想到用户输入完信息后因为滑动的关系有可能信息未被保存,这个时候我们可以想到三种方案来解决

planA :因为cell不多就考虑cell不复用

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
  self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.placeTFPlaceHolder = [[UITextField alloc]initWithFrame:CGRectMake(self.frame.size.width-200, 20, 180, 100)];
        [self.contentView addSubview:self.placeTFPlaceHolder];
        self.contentView.backgroundColor = [UIColor redColor];
        
    }
    return self;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSString * ID = [NSString stringWithFormat:@"%ld",indexPath.row];
    
    CustomerTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        
        cell = [[CustomerTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
    }
    
    //给cell中得属性framemodel赋值
    
    
    cell.textLabel.text = self.dataSource[indexPath.row];
    cell.placeTFPlaceHolder.placeholder = self.dataSource[indexPath.row];
    
    return cell;
}
planB:利用UITextfiled的代理去实现

破烂C:利用代理储存用户已经输入的信息去实现。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值