How do I pass variables between view controllers?

前端 未结 6 1395
礼貌的吻别
礼貌的吻别 2020-12-06 20:21

i\'m having a hard time with Xcode; for some reason, it just won\'t let me pass a variable from one view controller class to another. It should work, i was basically just co

6条回答
  •  温柔的废话
    2020-12-06 20:59

    Follow these simple steps please, it should work.

    In your SecondViewController:

    1. Create an initializer in the second View Controller. Ex:

      -(id)initWithResultsArray: (NSArray *) resultsArray;

    2. Create a variable for holding the array. Say myResultsArray.

    3. Inside the initWithResultsArray method, save the value of resultsArray to myResultsArray.

    4. Initialize the SecondViewController using initWithResultsArray instead of just init.

    5. Present your controller as usual, you will be able to work with myResultsArray.

    Hope this helps.

    Monica ツ

提交回复
热议问题