1
我發現了幾個與此類似的問題,但無法找到答案。我剛開始使用attributedText在我的標籤設置文本格式,它是引發此錯誤:當調用sizeToFit時發送到實例的無法識別的選擇器發生崩潰ios應用程序
-[__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];
我絕不是這方面的專家,任何建議或建議都非常感謝。
頭文件的情況下,它是需要:
#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
它看起來好像有些對象被釋放,當你不希望它是。我會在你的構建方案中打開殭屍,看看是否會給你一個更有用的錯誤信息。 –
看看你的'屬性字符串'字體設置,如果它仍然是最新的:https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSMutableAttributedString_Class/Reference/ Reference.html#// apple_ref/occ/instm/NSMutableAttributedString/addAttribute:value:range: https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/AttributedStrings/AttributedStrings.html#//apple_ref/doc/uid/10000036i – lootsch
那麼,異常堆棧顯示錯誤發生在哪裏?你是否在任何地方調用'isDefaultFace'? –