亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NSString 作為參數傳到另外個類的函數里報錯

NSString 作為參數傳到另外個類的函數里報錯

MMTTMM 2019-04-23 15:18:34
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貢獻1789條經驗 獲得超8個贊

樓上gaosboy正解,我只是做個補充,
因為NSString字符串是autorelease的,在多層方法傳遞賦值時會在中間某一層傳遞中釋放掉。分割線我說NSString是autorelease這個是錯誤的,NSString*str=@"123",這樣得到的字符串是字符串常量,并非autorelease。
這個是不對的,本意是表達在參數傳遞過程中NSString*str=obj;這樣得到的str是autorelease的。題外話:
immutablevalue盡量使用copy屬性
                            
查看完整回答
反對 回復 2019-04-23
  • 2 回答
  • 0 關注
  • 347 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號