iosAppQuestns
iosAppQuestns

Reputation: 17

how to pass data from one view to another view through parentviewcontroller

I have data in read.m class. i created parent view controller for read. so,parent view is home.m. in home.m i used present modal view controller for get retailer class. i want data from read.m to retailer.m through the home.m.

read.m 

-(void)requestFromtblViews:(id)navigation forIndex:(int)index forText:(NSString *)text withDBdata:(NSArray *)DBdata{
    [DBdata objectAtIndex:index];
}

-(void)showRetailerInfo 
{
    //NSLog(@"show retailer Information is....");
    [self.ReadViewContent  GetshowRetailerInfo:self];
}

home.m

-(void)GetshowRetailerInfo:(id)currentview;
{
    // NSLog(@"get retailer info....");
    Retailer_Info = [[RetailerInfoViewController alloc]initWithNibName:@"RetailerInfoViewController" bundle:[NSBundle mainBundle]];
    Retailer_Info.view.frame = CGRectMake(0, 0, 320, 480);
    [Retailer_Info loadDefaultView];
    [self presentViewController:Retailer_Info animated:YES completion:nil];
    [Retailer_Info release];
}

Upvotes: 0

Views: 117

Answers (3)

NightFury
NightFury

Reputation: 13546

Use delegate protocol.

In Home.h

@protocol RetailerDelegate <NSObject>

-(void) passDataToRetailer:(NSArray *)array;

@end

@interface Home:UIViewController
{
 Read readObj;
}
@property(assign, nonatomic) id <RetailerDelegate> delegate;

In Home.m

//call method where you want to pass data
[delegate passDataToRetailer:readObj.array];

In RetailerInfoViewController.h

@interface RetailerInfoViewController : UIViewController<RetailerDelegate>
{
 NSArray *localArray;
}

In RetailerInfoViewController.m

//in viewdidload
Home *parent = [self presentingViewController];
parent.delegate = self;

-(void) passDataToRetailer:(NSArray *)array
{
//here you receive your data
}

Hope this helps you...

Upvotes: 0

Jitendra
Jitendra

Reputation: 5081

if you want to acess the properties of another class first you need to import that .h file where you want and make object of that class. and access which method...

Suppose you need to acess the second view controller properties into FirstViewController.Then define SecondViewController.h file into FirstViewController.and make object

SecondViewController *controller = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:Nil];

controller.method;

// method what you want to access here...

Upvotes: 0

IronManGill
IronManGill

Reputation: 7226

Make the values or variables global . Declare the variables in Appdelegate and then import it where you want to. Also you can Make a singleton Class and import its values . It will be like passing values from one view to the other. As the variables will remain the same but the values will change according to your code.

Please have a look here :-

Passing Data between View Controllers

http://oleb.net/blog/2012/02/passing-data-between-view-controllers/

Upvotes: 1

Related Questions