Passing data between classes using Objective-C

后端 未结 4 715
时光取名叫无心
时光取名叫无心 2020-12-18 13:01

I need some info about how to pass data between classes.. To be specific, I want to store in a class in an array some info, (using model store class), and then use it in ano

相关标签:
4条回答
  • 2020-12-18 13:36

    I've posted some alternatives to the delegate pattern in Q&A What are alternatives to “delegates” for passing data between controllers?.

    0 讨论(0)
  • 2020-12-18 13:36
    1. just declare array(let array2) in second class(MYSecondView) and do not forget to set his propert and synthesize. and then go to first class in .h file and import class(#import "MySecondView") where you define array2.
    2. create an object of second class(MySecondView *objMySecondView=[MySecondView alloc]init];) in your first class. then pass value to array2 from array of first class. like

      objMySecondView.array2 setObjectFromArray=array1;
      
    0 讨论(0)
  • 2020-12-18 13:46

    You can do like:

    For example: you want to pass Array from FirstViewController to SecondViewController.

    Create Array in SecondViewController first and define it as property as in SecondViewController.h:

    NSMutableArray *secondArr;
    @property (nonatomic, retain) NSMutableArray *secondArr;
    

    In SecondViewController.m:

    @synthesize secondArr;
    

    Then, for example, you want to pass Array when a button in FirstViewController is touched. In its action (create IBAction, link it with the button's touchesUpInside), you can set it to get the instance of your second view controller, for example:

    secondViewController.secondArr = firstArr;
    
    0 讨论(0)
  • 2020-12-18 13:50

    If you don't know how to do that, it's seems that you're at the very beginning of learning Objective-c and OO programming. So you better have some time to read about it

    A good place to start is here

    0 讨论(0)
提交回复
热议问题