From 620be11f0d0c254e45cd59b4f71deb537842b968 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 21 Oct 2013 19:11:39 +0200 Subject: [PATCH] Fixed #93. Formatter are now cleaned up on reused table cell views --- MacPass/MPEntryViewController.m | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index dbded15b..b6ac6323 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -242,28 +242,36 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; } else { view = [tableView makeViewWithIdentifier:_MPTableStringCellView owner:self]; - if(isURLColumn) { - [[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"url" options:nil]; + NSTextField *textField = [view textField]; + 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) { - [[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"username" options:nil]; + [textField bind:NSValueBinding toObject:entry withKeyPath:@"username" options:nil]; } else if(isNotesColumn) { 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) { - [[view 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]; + [textField bind:NSValueBinding toObject:entry withKeyPath:@"binaries.@count" options:nil]; } } - return view; }