我在2個單元格內創建了2個文本框。桌面單元格內的ios textfield
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
if (indexPath.row == 0) {
[self CustomTextField:cell :txtFirstName];
txtFirstName.text = [_dictInfoOneUser objectForKey:@"firstname"];
[cell addSubview:txtFirstName];
txtFirstName.tag = 100;
}
else (indexPath.row == 1){
[self CustomTextField:cell :txtLastName];
txtLastName.text = [_dictInfoOneUser objectForKey:@"lastname"];
[cell addSubview:txtLastName];
txtLastName.tag = 101;
}
}
我想我設置了txtFirstName.text = [_dictInfoOneUser objectForKey:@"firstname"];
。我編輯了單元格的名字,之後,我滾動,它是刷新單元格並重置我在textfield中編輯的內容。
如何解決此問題。
************編輯
-(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];
}
有保存編輯信息?如果不是 - 比單元格中只有'默認'文本。 – Oleshko
可能會將編輯後的文本保存到NSMutableArray中(每次編輯時都要刪除並添加),並使用此可變數組來填充單元格。當您滾動時,tableview被重新加載。 – enzo
你可以編輯我的代碼嗎? –