Fixed #93. Formatter are now cleaned up on reused table cell views

This commit is contained in:
michael starke
2013-10-21 19:11:39 +02:00
parent 89105c6e90
commit 620be11f0d

View File

@@ -242,28 +242,36 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
} }
else { else {
view = [tableView makeViewWithIdentifier:_MPTableStringCellView owner:self]; view = [tableView makeViewWithIdentifier:_MPTableStringCellView owner:self];
if(isURLColumn) { NSTextField *textField = [view textField];
[[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"url" options:nil]; if(!isModifedColumn && !isNotesColumn) {
/* clean up old formatter that might be left */
NSLog(@"Cleaing formatter. %@", [textField formatter]);
[textField setFormatter:nil];
}
if(isModifedColumn) {
if(![[view textField] formatter]) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
[textField setFormatter:formatter];
}
[textField bind:NSValueBinding toObject:entry.timeInfo withKeyPath:@"lastModificationTime" options:nil];
return view;
}
else if(isURLColumn) {
[textField bind:NSValueBinding toObject:entry withKeyPath:@"url" options:nil];
} }
else if(isUsernameColumn) { else if(isUsernameColumn) {
[[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"username" options:nil]; [textField bind:NSValueBinding toObject:entry withKeyPath:@"username" options:nil];
} }
else if(isNotesColumn) { else if(isNotesColumn) {
NSDictionary *options = @{ NSValueTransformerNameBindingOption : MPStripLineBreaksTransformerName }; NSDictionary *options = @{ NSValueTransformerNameBindingOption : MPStripLineBreaksTransformerName };
[[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"notes" options:options]; [textField bind:NSValueBinding toObject:entry withKeyPath:@"notes" options:options];
} }
else if(isAttachmentColumn) { else if(isAttachmentColumn) {
[[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"binaries.@count" options:nil]; [textField bind:NSValueBinding toObject:entry withKeyPath:@"binaries.@count" options:nil];
}
else if(isModifedColumn) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
[[view textField] setFormatter:formatter];
[[view textField] bind:NSValueBinding toObject:entry.timeInfo withKeyPath:@"lastModificationTime" options:nil];
} }
} }
return view; return view;
} }