Passing a dictionary between two viewcontrollers?

前端 未结 2 1216
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 07:10

I have an application in which I have a webservice call that returns data as a dictionary. I want to access this dictionary in another view controller for loading the values

2条回答
  •  抹茶落季
    2021-01-17 07:26

    You could define an NSDictionary property in your AnotherViewController and set it from the previous controller. I'll give a brief example below.

    //.h
    @interface AnotherViewController {
    
      NSDictionary *data;
    }
    @property(nonatomic,retain) NSDictionary *data;
    @end
    
    //.m
    @implementation AnotherViewController
    @synthesize data;
    

    Now from the current controller, after initializing AnotherViewController you set the dictionary before presenting it.

    AnotherViewController *controller = [[AnotherViewController alloc] init];
    controller.data = myCurrentDictionary;
    

    Now AnotherViewController has a data property with the value of the previous controller.

    Hope this helps.

提交回复
热议问题