类似这样需要用户输入的时候要想到用户输入完信息后因为滑动的关系有可能信息未被保存,这个时候我们可以想到三种方案来解决
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:利用代理储存用户已经输入的信息去实现。