在CLASSA我有:爲什麼nsstring在另一個類中使用時不見了?
classB *classBI=[[classB alloc]init];
bits=[classBI data]; //bits has a property here in classA,it gets data from B/
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(38.f, 20.f, 244.f, 43.f)];
label.text = bits;
在CLASSB我有:
@property (nonatomic,retain) NSString *data; //in .h file
[email protected]"no data"; //at the init method of classB .
//then after a while when something is happen in classB , data is changed to :
data=[NSString stringWithFormat:@"data:%f,%f,%f,%f,%f,%f",
dataBits[0],dataBits[1],dataBits[2],dataBits[3],dataBits[4],dataBits[5] ];
ClassA的是主場景(cocos2d的,但它並不重要)。在開始的時候,我可以在標籤中看到classA中的「無數據」這個詞,但是當classB中的數據發生變化時,我無法看到屏幕上標籤的變化。它留下的字:「沒有數據」 這是爲什麼? 爲什麼我丟失了數據? 如果我在classB中的NSLOG數據,在它改變之後,我可以看到它不爲空,並且它具有新的值。 B的實例在A中出現了這個字符串,這是錯誤的。
你必須從某個地方更新標籤!設置一次不會自動將它「綁定」到b類的值。你在哪裏更新標籤? – Mario
我不..但它的指針 - 它沒有得到值「永遠」? – Curnelious
不,它指向**字符串**,表示「無數據」。當您將數據設置爲新字符串時,位仍舊指向舊字符串。 – lnafziger