iPhone: How to Pass Data Between Several Viewcontrollers in a Tabbar App

后端 未结 3 977
眼角桃花
眼角桃花 2020-11-27 04:52

I have following problem:

I have built a tabbar application with 4 tabs. I want to pass a object/variable from the first tab controller to the third one and initiali

3条回答
  •  一整个雨季
    2020-11-27 05:09

    I don't think this is best practice (also check syntax) however I have got away with:

    in the .h

    otherclassref *otherclassname
    
    @property (assign) otherclassname otherclassref;
    

    and in the .m

    @synthesize otherclassref;
    

    then I just assign the reference from somewhere convenient e.g. the app delegate or wherever you are instantiating your viewcontrollers.

    then the view controller can get a reference to the other view controller.

    I add @class secondviewcontroller to the .h file for the firstviewcontroller and put put the #imports "secondviewcontroller.h" in the .m file of the first view controller. These are called forward references and prevent compiler errors resulting from having .h files referencing each other.

提交回复
热议问题