调用sizeToFit时,ios应用程序崩溃,无法识别的选择器发送到实例
我发现了一些类似的问题,但找不到答案。我刚开始使用AttributeText格式化标签中的文本,它引发了以下错误:调用sizeToFit时,ios应用程序崩溃,无法识别的选择器发送到实例,ios,objective-c,Ios,Objective C,我发现了一些类似的问题,但找不到答案。我刚开始使用AttributeText格式化标签中的文本,它引发了以下错误: -[__NSCFType _isDefaultFace]: unrecognized selector sent to instance 0x20880f40 2014-03-18 19:44:57.039 appName[317:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentExc
-[__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))];
}
}
它在执行这一行时抛出错误代码>
我绝对不是这方面的专家,任何建议都是非常感谢的
需要时的头文件:
#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
#导入
#导入“ServiceConnector.h”
#导入“Global.h”
@接口RestaurantDetail:UIViewController{
IBUIScrollView*滚动条;
}
@属性(非原子,保留)IBUIImageView*imgCompany;
@属性(非原子,保留)IBUILabel*lblTopName;
@属性(非原子,保留)IBUILABEL*lblReward;
@属性(非原子,保留)IBUILABEL*lblCity;
@属性(非原子,保留)IBUILabel*lblStreet;
@属性(非原子,保留)IBUIButton*btnStreet;
@属性(非原子,保留)IBUILabel*lblDistance;
@属性(非原子,保留)IBUIButton*btnReward;
@属性(非原子,保留)IBUILabel*LBL描述;
@财产(非原子,保留)餐厅Fo*curInfo;
@属性(非原子,保留)BonusInfo*BonusInfo;
@财产(非原子,保留)NSString*网站;
-(iAction)反向单击;
-(iAction)点击获取报酬;
-(iAction)术语被勾选;
-(无效)获取详细信息;
-(无效)详细信息;
-(i)街景;
//服务连接器委托
-(无效)请求返回的数据:(NSData*)数据;
-(无效)alertView:(UIAlertView*)alertView单击按钮索引:(NSInteger)按钮索引;
@结束
感谢所有发表评论的人。这让我找到了正确的方向来解决这个问题。这似乎是一个内存问题,虽然我不完全理解它,但它不喜欢我如何变异我的属性字符串
我改变了这个
[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)];
谢谢大家的评论。这让我找到了正确的方向来解决这个问题。这似乎是一个内存问题,虽然我不完全理解它,但它不喜欢我如何变异我的属性字符串 我改变了这个
[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)];
它看起来像是某个对象在您不希望它被释放时被释放。我会在你的构建方案中打开僵尸,看看这是否会给你带来更有用的错误消息。看看你的
属性字符串字体设置,如果它仍然是最新的::那么,异常堆栈在哪里显示错误发生?您是否在任何地方调用isDefaultFace
anywhere?(似乎是UIFont的一种方法,对于“无法识别的选择器”非常流行)。而且它似乎在任何地方都没有文档记录,但NSCFType似乎是分配给已释放对象的类型,进一步表明这是一个僵尸问题。它看起来像是某个对象在你不希望它被释放的时候被释放了。我会在你的构建方案中打开僵尸,看看这是否会给你带来更有用的错误消息。看看你的属性字符串字体设置,如果它仍然是最新的::那么,异常堆栈在哪里显示错误发生?您是否在任何地方调用isDefaultFace
anywhere?(似乎是UIFont的一种方法,对于“无法识别的选择器”来说非常流行)。而且它似乎在任何地方都没有文档记录,但NSCFType似乎是分配给已释放对象的类型,进一步表明这是一个僵尸问题。