开发者

iphone, pass an array between classes? [closed]

开发者_StackOverflow中文版 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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


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.


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/


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜