2015-02-17 3 views
-2

Я получаю исключение в моем iPhone-приложении,находка исключения «непризнанный селектор послало к экземпляру» происходит только в iOS6

-[__NSCFString sizeWithAttributes:]: unrecognized selector sent to instance, 

, когда я начинаю мое приложение Üner iOS6.1 под iOS7 или выше все ОК. Единственное различие между iOS6 и выше в моем проекте - это XIB. Ошибка возникает, когда я нажимаю кнопку. Возможно, это исходит из разных XIB, может быть, нет.

Похоже на утечку памяти, но я не могу понять, почему это происходит. Исключение возникает при попытке рассчитать размер текста с помощью кнопки.

Я установил контрольные точки исключения, чтобы найти ошибку. Вот некоторые из информация о StackTrace:

В этом методе происходит ошибка:

- (float) calculateButtonWidth:(TypeButtonRest*) typeButtonRest{ 

    UIFont *font = [UIFont boldSystemFontOfSize:16]; 
    NSDictionary *userAttributes = @{NSFontAttributeName: font, 
        NSForegroundColorAttributeName: [UIColor blackColor]}; 
    const CGSize textSize = [[typeButtonRest text] sizeWithAttributes: userAttributes]; 
    ... 

Метод называется здесь:

- (ButtonMatrixInfos*) calculateButtonSchema:(NSMutableArray*) buttons screenWidth:(double)screenWidth minMargin:(double)minMargin{ 
    ButtonMatrixInfos *returnValue = [[[ButtonMatrixInfos class] alloc] init]; 
    int buttonCount = [buttons count]; 
    [buttons retain]; 
    for (int i=0; i < buttonCount; i++) { 
     float curWidth = [self calculateButtonWidth:[buttons objectAtIndex:i]]; 
     maxButtonWidth = curWidth > maxButtonWidth ? curWidth : maxButtonWidth; 
    } 
    ... 

Мое предположение, что buttons поврежден. Они идут отсюда:

-(RadioButtonContainer*)addRadioButtons:(NSMutableArray *)buttons withButtonGroupName:(NSString*) groupName andMarginLeft:(int) marginLeft andMarginRight:(int) marginRight preselected:(NSString*) preselected { 
ButtonListLayouter *bll = [[[[ButtonListLayouter class] alloc] init]retain]; 
ButtonMatrixInfos *bmi = [bll calculateButtonSchema:buttons screenWidth:(screenSize.width - marginLeft - marginRight) minMargin:5]; 
... 

Создано здесь:

NSMutableArray *buttonsRest = [[[NSMutableArray alloc] init]retain]; 
for (int i=0; i < [buttons count]; i++) { 
    TypeButtonRest *tpr = [[[[TypeButtonRest class] alloc] init]retain]; 
    tpr.text = [[buttons objectAtIndex:i] objectForKey:@"value"]; 
    tpr.key = [[buttons objectAtIndex:i] objectForKey:@"key"]; 
    [buttonsRest addObject:tpr]; 
} 

Я надеюсь, что это codefragments может помочь.

наилучшими пожеланиями

+0

О, хорошо, спасибо. Есть ли в iOS6 эквивалент? – BHuelse

ответ

3

sizeWithAttributes доступна только начиная с прошивкой 7.0. Вы хотите использовать sizeWithFont в iOS 6. Подробнее here