我有一个从nib文件创建的表视图单元格。 tableview中有不同的单元格,要通过键盘输入,我必须在屏幕上滚动tableview。现在的问题是,当我这样做时,我的单元格值被清除。
我知道当视图关闭并在屏幕上时会重新创建单元格,但更糟糕的是我的用户默认变量在此时为空并且我得到空文本字段。
要确认该值仍在用户默认值中,当我重新加载值返回的应用程序时。
这就是我创建tableviewcell的方式
else if ([indexPath row] == 4)
{
static NSString *WeeklyHoursCellIdentifier = @"WeeklyHoursCell";
WeeklyHourTableViewCell *tempTextfieldcell = (WeeklyHourTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:WeeklyHoursCellIdentifier];
if (tempTextfieldcell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"WeeklyHourTableViewCell" owner:self options:nil];
tempTextfieldcell = calculateTextFieldTableViewCell;
self.calculateTextFieldTableViewCell = nil;
}
if ([prefs objectForKey:@"iPhoneWeeklyHours"] != nil) {
tempTextfieldcell.textField.text = [prefs objectForKey:@"iPhoneWeeklyHours"];
}
任何想法的人。我真的被困在这里了。
由于
答案 0 :(得分:0)
以上代码完全没问题。我在代码中发现了错误。我正在为[prefs objectForKey:@" iPhoneWeeklyHours"]分配null,这是我需要避免的。
感谢大家花时间回答这个问题。