【发布时间】:2011-08-03 20:16:34
【问题描述】:
我正在使用分组的 UITableView 来显示我的应用程序首选项。
我得到了这个单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger section = [indexPath section];
NSInteger row = [indexPath row];
NSInteger identifier = row + ((section + 1) * 10);
NSString *CellIdentifier = [NSString stringWithFormat:@"CustomCellIdentifier-%d",identifier];
LoginTableViewCell *cell = (LoginTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LoginTableViewCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
cell.field.tag = identifier;
if (section == 0) {
switch (row) {
case 0:{
NSString *user = [[NSUserDefaults standardUserDefaults] valueForKey:@"username"];
cell.field.text = user;
cell.label.text = @"User";
break;
}
case 1:{
NSString *bundleName = [[NSBundle mainBundle] bundleIdentifier];
NSError *error = nil;
NSString *user = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
NSString *pwd = [SFHFKeychainUtils getPasswordForUsername:user andServiceName:bundleName error:&error];
cell.field.text = pwd;
cell.field.secureTextEntry = YES;
cell.label.text = @"Password";
break;
}
case 2:{
NSString *numero = [[NSUserDefaults standardUserDefaults] valueForKey:@"numero"];
cell.field.text = numero;
cell.field.keyboardType = UIKeyboardTypePhonePad;
cell.label.text = @"Number";
break;
}
default:
break;
}
if (cell.field.text > 0) {
cell.field.enabled = NO;
cell.field.borderStyle = UITextBorderStyleNone;
}
} else {
switch (row) {
case 0:{
cell.field.text = [NSString stringWithFormat:@"+%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"prefix"]];
cell.field.keyboardType = UIKeyboardTypePhonePad;
cell.label.text = @"Prefix";
break;
}
case 1:{
cell.field.text = [[NSUserDefaults standardUserDefaults] valueForKey:@"sender"];
cell.field.keyboardType = UIKeyboardTypeNamePhonePad;
cell.label.text = @"Sender";
break;
}
default:
break;
}
}
}
return cell;
}
问题是,当一行滚动到窗口外时,文本字段为空。
如何防止这种情况发生?
我认为缓存是正确的解决方案,但即使使用可重用标识符,我仍然遇到同样的问题。
【问题讨论】:
标签: iphone uitableview scroll uitextfield editing