0

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];
}
Florian Mielke
  • 3,310
  • 27
  • 31
iosAppQuestns
  • 17
  • 1
  • 8

3 Answers3

1

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/

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52
  • I DONT WANT CREATE INSTANCE IN APPDELEGATE. HOME IS PARENTCONTROLLER FOR READ. I AM GETTING DATA IN READ.M. HOW TO GET DATA IN HOME?. IF I WILL CREATE INSTANCE FOR HOME IN READ, I AM GETTING ERROR- UNUSED VARIABLE LIKE THIS – iosAppQuestns Jul 31 '13 at 05:41
  • See the obvious way is you will have to create a global variable.... Or import your read.m in your home.m ... create variables in the .h file .... – IronManGill Jul 31 '13 at 05:43
  • read.m -(void)requestFromtblViews:(id)navigation forIndex:(int)index forText:(NSString *)text withDBdata:(NSArray *)DBdata { [DBdata objectAtIndex:index]; nslog("%@",dBdata)}. AM GETIND DBDATA IN THIS METHOD ONLY. i WANT TO PASS THIS DATA THROUGH [(RETAILER *)RETAILER loadViewForArray:[DBdata objectAtIndex:index]];METHOD IN -(VOID)SHOWRETAILERINFO IN READ.M – iosAppQuestns Jul 31 '13 at 05:56
  • DBDATA IS ARRAY. I AM GETTING DATA FROM DATABASE IN THIS METHOD. – iosAppQuestns Jul 31 '13 at 06:00
  • i got data in instance method in read.m. how to pass that data to retailer class. retailer is allocated in home. and implemented present modal view controller – iosAppQuestns Jul 31 '13 at 09:31
  • i am not getting like this – iosAppQuestns Aug 01 '13 at 04:50
0

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...

NightFury
  • 13,436
  • 6
  • 71
  • 120
  • CHILD IS READ. READ PARENT IS HOME. THROGH HOME I WANT TO PASS THE DATA IN METHOD TO REATAIL – iosAppQuestns Jul 31 '13 at 06:03
  • i got data in instance method in read.m. how to pass that data to retailer class. retailer is allocated in home. and implemented present modal view controller – iosAppQuestns Jul 31 '13 at 09:29
  • @Ram So you want read class object which is present as instance in home, pass data to Retailer(presented modally on home). Am I right? – NightFury Jul 31 '13 at 10:35
0

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...

Jitendra
  • 5,055
  • 2
  • 22
  • 42
  • i got data in instance method in read.m. how to pass that data to retailer class. retailer is allocated in home. and implemented present modal view controller – iosAppQuestns Jul 31 '13 at 09:28
  • you need to create objcet of that class and aceess using that object like object.property... – Jitendra Jul 31 '13 at 09:30
  • in read if i will create object to home, am getting error. unused variable – iosAppQuestns Jul 31 '13 at 09:37
  • If you want to create any other class objcet into next class ffirst need to declare that class in .h #import "" Like this and then create objcet and then SecondViewController *controller = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:Nil]; controller.method; – Jitendra Jul 31 '13 at 09:46