在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