简体   繁体   中英

ios app crashing with unrecognized selector sent to instance when sizeToFit is called

I have found a few questions similar to this but cannot find the answer. I just started using attributedText to format text in my labels and it is throwing this error:

-[__NSCFType _isDefaultFace]: unrecognized selector sent to instance 0x20880f40
2014-03-18 19:44:57.039 appName[317:907] *** Terminating app due to uncaught exception     'NSInvalidArgumentException', reason: '-[__NSCFType _isDefaultFace]: unrecognized selector sent to instance 0x20880f40'

This is my method

-(void) SetDetails
{
if(_curInfo)
{

    NSUInteger length=[_curInfo.company_name length];
    NSString* des = [NSString stringWithFormat:@"%@\r%@\r\r", _curInfo.company_name, _curInfo.description];
    NSUInteger length2=[des length];

    NSString* descript = [NSString stringWithFormat:@"%@\r%@\r\rTerms\r%@", _curInfo.company_name, _curInfo.description, _curInfo.terms];
    NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:descript];

    [attrStr setFontName:@"System - System Bold" size:17 range:NSMakeRange(0, length)];
    [attrStr setTextBold:YES range:NSMakeRange(0, length)];

    [attrStr setFontName:@"System - System Bold" size:17 range:NSMakeRange(length2, 5)];
    [attrStr setTextBold:YES range:NSMakeRange(length2, 5)];



    _lblDescription.attributedText=attrStr;





    [_lblDescription sizeToFit];




    _lblReward.text=_curInfo.reward;

    CGFloat scrollViewHeight = 0.0f;
    for (UIView* view in scroller.subviews)
    {
        scrollViewHeight += view.frame.size.height;

    }

    [scroller setContentSize:(CGSizeMake(320, scrollViewHeight))];

}
}

It is throwing the error when it executes this line [_lblDescription sizeToFit];

I am by no means an expert at this, any suggestions or advice is much appreciated.

Header file in case it is needed:

#import <UIKit/UIKit.h>
#import "ServiceConnector.h"
#import "Global.h"

@interface RestaurantDetail : UIViewController<ServiceConnectorDelegate, UIAlertViewDelegate>{
    IBOutlet UIScrollView *scroller;

}

@property (nonatomic, retain) IBOutlet UIImageView* imgCompany;
@property (nonatomic, retain) IBOutlet UILabel* lblTopName;
@property (nonatomic, retain) IBOutlet UILabel* lblReward;
@property (nonatomic, retain) IBOutlet UILabel* lblCity;
@property (nonatomic, retain) IBOutlet UILabel* lblStreet;
@property (nonatomic, retain) IBOutlet UIButton* btnStreet;

@property (nonatomic, retain) IBOutlet UILabel* lblDistance;
@property (nonatomic, retain) IBOutlet UIButton* btnReward;
@property (nonatomic, retain) IBOutlet UILabel* lblDescription;

@property (nonatomic, retain) RestaurantInfo*   curInfo;
@property (nonatomic, retain) BonusInfo*        bonusInfo;
@property (nonatomic, retain) NSString*        website;


-(IBAction)BackClicked;
-(IBAction)GetRewardClicked;
-(IBAction)TermsClicked;
-(void) GetDetails;
-(void) SetDetails;
- (IBAction)StreetClicked;

// service connector delegate
- (void)requestReturnedData:(NSData*)data;

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

@end

Thank you to everyone who commented. It got me pointed in the right direction to figure this one out. It did appear to be a memory issue, although I do not understand it fully, it did not like how I was mutating my attributed string.

I changed this

[attrStr setFontName:@"System - System Bold" size:17 range:NSMakeRange(0, length)];
[attrStr setTextBold:YES range:NSMakeRange(0, length)];

to this

[attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17] range:NSMakeRange(0, length)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM