0

I want pass an array from Class A to Class B, but A calls B.

Doom
  • 1,258
  • 3
  • 15
  • 24

3 Answers3

0

What you want are simple object members to set. The best way to achive this is to use properties: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html#//apple_ref/doc/uid/TP40007594

in B.h:

@property(nonatomic,retain) NSArray * theArray_B;

in B.m:

@synthesize theArray_B;

in A.m:

myB_Instance.theArray_B = theArrayToPass;

In that example A and B share a pointer to the same Array-Object in Memory. Moreover B owns this Array (what A also does) as it has a retain on it.

Rene Berlin
  • 1,171
  • 7
  • 21
0

Something like this:

Class A contains:

- (void)someMethodInClassA {
    NSArray *arrayData = // ... stuff

    ClassB *classB = // ... stuff

    [classB aMethod:arrayData];

}

Class B contains:

- (void)aMethod:(NSArray *)array {
    // do something with the array
}

Google for objective c tutorials. You'll find things like http://howtomakeiphoneapps.com/objective-c-tutorial/

occulus
  • 16,959
  • 6
  • 53
  • 76
0

use this.

make array in class a and make it propertyand synthesize it in .m file. then push to next view and then use the pick object from navigation stack for accesing array.see this.

 FirstView *obj=(FirstView *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-2];

 //obj.array is the array which you want to use.
Ishu
  • 12,797
  • 5
  • 35
  • 51