我在2个单元格中创建了2个文本字段。
txtFirstName.text = [_dictInfoOneUser objectForKey:@"firstname"];
我想我设置了-(void)CustomTextField :(UITableViewCell *)cell :(UITextField *)textField{
//add bottom border
CALayer *border = [CALayer layer];
border.borderColor = [UIColor grayColor].CGColor;
border.frame = CGRectMake(cell.frame.size.width / 2 - 160, textField.frame.size.height - 1, textField.frame.size.width, textField.frame.size.height);
border.borderWidth = 1;
[textField.layer addSublayer:border];
textField.layer.masksToBounds = YES;
[textField setTextAlignment:NSTextAlignmentCenter];
}
。我编辑了单元格的名字,之后,我滚动,刷新单元格并重置我在文本字段中编辑的内容。
如何解决此问题。
************已编辑
session()->regenerateToken();
答案 0 :(得分:1)
看来你首先没有对你的牢房进行欺骗,这就是你的
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
应该是这样的:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
...
}
答案 1 :(得分:0)
这是由于细胞重用。要遵循的模式是有条件地构建子视图(因此每个单元只能获得一个),但无条件地配置它们。像这样......
if (indexPath.row == 0) {
UITextField *txtFirstName = (UITextField *)[cell viewWithTag:100];
if (!txtFirstName) {
// it doesn't exist. build it
[self CustomTextField:cell :txtFirstName]; // not sure what this does, assuming it's part of building it
[cell addSubview:txtFirstName];
txtFirstName.tag = 100;
}
// whether it was just built or not, give it a value
txtFirstName.text = [_dictInfoOneUser objectForKey:@"firstname"];
}
// same idea for the other row/textfield