From 097d8ea042e9545bce160fa3001d53fc74611537 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 31 Mar 2010 16:36:23 +0000 Subject: check for the attributed string length >= 3 while truncating it to avoid exceptions --- Source/SPFavoriteTextFieldCell.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index 1ef39348..f9025f63 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -152,7 +152,7 @@ if (maxWidth < mainStringWidth) { for (i = 0; i <= [mainString length]; i++) { - if ([[mainString attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth) { + if ([[mainString attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth && i >= 3) { mainString = [[[NSMutableAttributedString alloc] initWithString:[[[mainString attributedSubstringFromRange:NSMakeRange(0, i - 3)] string] stringByAppendingString:@"..."] attributes:[self mainStringAttributedStringAttributes]] autorelease]; } } @@ -160,7 +160,7 @@ if (maxWidth < subStringWidth) { for (i = 0; i <= [subString length]; i++) { - if ([[subString attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth) { + if ([[subString attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth && i >= 3) { subString = [[[NSMutableAttributedString alloc] initWithString:[[[subString attributedSubstringFromRange:NSMakeRange(0, i - 3)] string] stringByAppendingString:@"..."] attributes:[self subStringAttributedStringAttributes]] autorelease]; } } -- cgit v1.2.3