2014-04-09 23 views
1

我在依奧斯的研究與開發初學者,我一個深化發展應用tabed但我想從每個視圖訪問的屬性,所以我寫這篇文章的appDelegate: @property (strong, nonatomic) NSString *test; 但現在我不知道如何從我的firstViewController.m和secondViewController.m依奧斯tabed應用@property

回答

4

訪問此字符串您需要創建AppDelegate類喜歡的對象: -

AppDelegate *del = [[UIApplication sharedApplication]delegate]; 

,並使用del.test用這個定義字符串中的任何一類。不要忘記將你的Appdelegate類導入到你想使用它的字符串的特定類中。還有@synthesize你的字符串也是.m appdelegate類。

更新: -

如果您希望使用特別的類,那麼進口的appdelegate的appdelegate對象在像.h文件中: - 在

enter image description here

和.M類ViewDidLoad

enter image description here

+0

型鑄造DELE門實例到AppDelegate類將避免警告。 'AppDelegate * del =(AppDelegate *)[[UIApplication sharedApplication] delegate];' – Amar

+0

sir如果你沒有導入Appdelegate類到特定的類,那麼你有警告。如果你不能beleve然後我沒有警告添加屏幕截圖。我用這行代碼附​​加到我的答案中。而在其他情況下,你是在.h文件中定義appdelegate的對象,並使用這個對象的特定類,那麼你是對的。與以上 –