为了账号安全,请及时绑定邮箱和手机立即绑定

NSString 作为参数传到另外个类的函数里报错

NSString 作为参数传到另外个类的函数里报错

慕少森 2019-04-06 08:31:50
ValueObject#import@interfaceCurrentDataVO:NSObject@property(nonatomic,retain)NSString*crt;@property(nonatomic,retain)NSString*last;@property(nonatomic,retain)NSString*dataType;@property(nonatomic,retain)NSString*date;@property(nonatomic,retain)NSMutableArray*days;@property(nonatomic,retain)NSString*cv;-(void)showAllData;#import"CurrentDataVO.h"@implementationCurrentDataVO@synthesizecrt;@synthesizelast;@synthesizedataType;@synthesizedate;@synthesizedays;@synthesizecv;-(id)init{self=[superinit];if(self){days=[[NSMutableArrayalloc]init];}returnself;}-(void)showAllData{NSLog(@"%@",crt);NSLog(@"%@",last);NSLog(@"%@",dataType);NSLog(@"%@",date);NSLog(@"%@",cv);NSLog(@"%@",days);}@endViewCtrlA[cellsetContentData:todayDatawithYesData:vo.last];ViewCtrlB-(void)setContentData:(NSString*)todayDatawithYesData:(NSString*)yesData{[todayDataLabelsetText:todayData];[yesDataLabelsetText:yesData];}cell不为nil在ViewCtrlB中NSlog能打印出todayData,但是赋值到setText中时会抛出异常。2012-12-1314:10:35.510mbaforios[29723:fb03]10052012-12-1314:10:35.511mbaforios[29723:fb03]-[__NSCFNumberisEqualToString:]:unrecognizedselectorsenttoinstance0x6b904e02012-12-1314:10:35.511mbaforios[29723:fb03]***Terminatingappduetouncaughtexception'NSInvalidArgumentException',reason:'-[__NSCFNumberisEqualToString:]:unrecognizedselectorsenttoinstance0x6b904e0'***Firstthrowcallstack:(0x12f10220x17a2cd60x12f2cbd0x1257ed00x1257cb20x46a0ff0x7abd0x440c0x93d90xd2da490xd2be840xd2cea70xd2be3f0xd2bfc50xc70f5a0x1a52a390x1b1f5960x1b1f8610x1a491200x1b1f1170x1a48fbf0x12c594f0x1228b430x12284240x1227d840x1227c9b0x1fab7d80x1fab88a0x32a6260x2ad20x2a45)terminatecalledthrowinganexception(lldb)
查看完整描述

2 回答

?
白板的微信

TA贡献1883条经验 获得超3个赞

做个补充,因为NSString字符串是autorelease的,在多层方法传递赋值时会在中间某一层传递中释放掉。分割线我说NSString是autorelease这个是错误的,NSString*str=@"123",这样得到的字符串是字符串常量,并非autorelease。这个是不对的,本意是表达在参数传递过程中NSString*str=obj;这样得到的str是autorelease的。题外话:immutablevalue尽量使用copy属性
查看完整回答
反对 回复 2019-04-06
  • 2 回答
  • 0 关注
  • 353 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信