[英]ios app crashing with unrecognized selector sent to instance when sizeToFit is called
我发现了一些与此类似的问题,但找不到答案。 我刚刚开始使用attributedText格式化标签中的文本,这引发了此错误:
-[__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'
这是我的方法
-(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))];
}
}
执行此行[_lblDescription sizeToFit];
时将[_lblDescription sizeToFit];
我绝不是专家,任何建议或建议都非常感谢。
头文件(如果需要):
#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
谢谢所有发表评论的人。 它使我指出了正确的方向,以弄清这一点。 它确实确实是一个内存问题,尽管我不太了解它,但它不喜欢我如何更改属性字符串。
我改变了这个
[attrStr setFontName:@"System - System Bold" size:17 range:NSMakeRange(0, length)];
[attrStr setTextBold:YES range:NSMakeRange(0, length)];
对此
[attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17] range:NSMakeRange(0, length)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.