【发布时间】:2012-01-05 02:54:14
【问题描述】:
我的UITableViewCell 中有一个UITextField,在一个UITableView 中。我总共有 11 个单元格。当我在单元格中输入文本并将单元格滚动到屏幕外时,该文本将被清除。
似乎单元格正在出队或解除分配。只有 11 个,所以问题不大,但我怎样才能让所有单元格的 textFields 在此视图中始终可见?
这是我正在使用的代码。是因为我没有诸如数组之类的数据源吗?如果服务器有文本,我将从childAppointmentDictionary 中提取文本,否则用户输入文本并将其保存到NSString。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CellIdentifier = @"textCell";
VitalsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
switch (indexPath.row) {
case 0:
cell.vitalsLabel.text = @"Temperature";
cell.textField.text = [self.childAppointmentDictionary objectForKey:@"temperature"];
self.temperatureTextField = cell.textField;
break;
case 1:
cell.vitalsLabel.text = @"Pulse";
cell.textField.text = [self.childAppointmentDictionary objectForKey:@"pulse"];
self.pulseTextField = cell.textField;
break;
default:
break;
}
return cell;
}
- (void) textFieldDidEndEditing:(UITextField *)textField{
if (textField == temperatureTextField){
self.temperatureString = self.temperatureTextField.text;
}
else if (textField == pulseTextField){
self.pulseString = self.pulseTextField.text;
}
}
【问题讨论】:
-
你能显示你的
cellForRowAtIndexPath方法的代码吗? -
我可以使用
UIScrollView复制这个UITableView的外观吗?这会解决我遇到的一些问题吗?
标签: iphone memory-management uitableview uitextfield