Handle the case when the vertical candidate data source is gone.

This commit is contained in:
Lukhnos D. Liu 2012-03-29 21:04:30 -07:00
parent b0b5dd0233
commit 005437db28
1 changed files with 8 additions and 2 deletions

View File

@ -197,8 +197,14 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{ {
NSString *candidate = [_delegate candidateController:self candidateAtIndex:row]; NSString *candidate = @"";
// rendering can occur when the delegate is already gone or data goes stale; in that case we ignore it
if (row < [_delegate candidateCountForController:self]) {
candidate = [_delegate candidateController:self candidateAtIndex:row];
}
NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:candidate attributes:[NSDictionary dictionaryWithObjectsAndKeys:_candidateFont, NSFontAttributeName, _candidateTextParagraphStyle, NSParagraphStyleAttributeName, nil]] autorelease]; NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:candidate attributes:[NSDictionary dictionaryWithObjectsAndKeys:_candidateFont, NSFontAttributeName, _candidateTextParagraphStyle, NSParagraphStyleAttributeName, nil]] autorelease];
// we do more work than what this method is expected; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead // we do more work than what this method is expected; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead