【发布时间】:2014-11-27 21:17:56
【问题描述】:
我有这个 tableview 有足够的单元格需要滚动,每个单元格都是一个包含标签和 UITextField 的自定义单元格。我正在尝试this 解决方案
当我在文本字段中输入文本并滚动表格视图以查看其他单元格时,我之前编写的文本消失了,留下一个空白文本字段。
This 是我遇到的问题
我的 cellForRowAtIndexPath 代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Mycell";
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.myLabel.text = [labelarray objectAtIndex:indexPath.row];
cell.myTextbox.tag = indexPath.row;
cell.myTextbox.text = stringVariable;
return cell;
}
stringVariable 在 .h 中声明
interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>{
NSMutableArray *labelarray ;
NSString *stringVariable;
__weak IBOutlet UITableView *myTableview;
}
我在这里初始化了它:
-(void)textFieldDidEndEditing:(UITextField *)textField{
MyTableViewCell *cell;
stringVariable = [[NSString alloc]init];
if (textField == cell.myTextbox) {
self->stringVariable = cell.myTextbox.text;
}
}
【问题讨论】:
标签: ios uitableview ios8 uitextfield