0

I'm using JSONModel in my objective c application. I get all data to my JSONModel in a first abBarController. Then I need get this data in other viewController. I'm trying send this data to the others viewControllers like:

First ViewController:

@implementation FirstViewController 
...
SecondViewController* infoController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];
SecondViewController.model = self.model;//Here send the model with data
[self.navigationController pushViewController:infoController animated:YES];
...
@end

Second ViewController:

@interface SecondViewController :UIViewController{
 MyModel *model;
}

@property MyModel *model;

There is a better form to keep this data model instantiated and get the model data from another viewController without send this in a property?

user3745888
  • 6,143
  • 15
  • 48
  • 97

3 Answers3

1

Create object class

In .h object class

@interface FirstModel : NSObject{
 }
@property(nonatomic,strong)NSMutableArray *productsArray;

In .m object Class

-(id)init{
    self=[super init];
    if (self) {

        _productsArray=[[NSMutableArray alloc]init];

    }
    return self;
}

Create another one Object Class

@interface SecondModel : NSObject
@property (nullable,nonatomic, retain) NSString *name;
@end

In TableviewViewcontroller .h file Import Two Object class and insert the following coding

@property(nonatomic,strong)FirstModel *firstListObject;

In .m file //cell for rowAt Indexpath

SecondModel *prodObj=_firstListObject.productsArray[indexPath.item];
cell.productNameLabel.text=prodObj.name;

You may have access this object class wherever you need…

Sathish Kumar VG
  • 2,154
  • 1
  • 12
  • 19
0

You can use a singleton class, create your model property. In another viewController, you can access your model through instance of singleton. Reference http://www.idev101.com/code/Objective-C/singletons.html

Dan
  • 140
  • 1
  • 6
0

or you can archive it to the local files using plist or data-base

jolin
  • 1