您的位置:首页 > 产品设计 > UI/UE

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

2017-11-06 15:47 369 查看


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

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:利用代理储存用户已经输入的信息去实现。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: