How do I share an object between UIViewControllers on iPhone?

前端 未结 5 733
清酒与你
清酒与你 2020-11-28 22:48

My application is a tab bar application, with a separate view controller for each tab.

I have an object in my first view controller (A) which contains all my stored

5条回答
  •  星月不相逢
    2020-11-28 23:13

    The most common way I've seen this is to set up the thing you want to access in the app delegate and reference it in other places like this:

    MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    myStuff = appDelegate.stuff;
    

    In the app delegate, set up a stuff variable and use @property and @synthesize as usual.

    Some people say that it's not a good approach, since it's the same as using global variables, but it's very common.

提交回复
热议问题