我知道那裏有關於全局變量的各種帖子,但沒有任何幫助。 我的問題是 - 在我的AppDelegate.h中,我聲明瞭兩個變量x和y。在我的ClassA的,我進口AppDelegate.h並補充說:iPhone:目標C全局變量
AppDelegate mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
和分配值mainDelegate.x
和mainDelegate.y
。
在ClassB的,我分配這些X和Y
label1.text = mainDelegate.x;
label2.text = mainDelegate.y;
沒有錯誤,但它是null..nothing顯示爲標籤的文本。
任何人都可以請幫助..
編輯: 在AppDelegate.h:
@property (nonatomic, copy) NSString *x,*y;
在ClassA.m
mainDelegate.x=[[NSString alloc] initWithString:[homeArray objectAtIndex:indexPath.row]];
這mainDelegate.x我試圖從獲得ClassB,它是空的。
你是怎麼聲明x和y的?他們是屬性嗎? – Abizern
請提供一些代碼片段。 –
在AppDelegate.h中聲明x和y '@property(nonatomic,retain)NSString x,y;' – dinny