NSMutable Array from One Class to Another Class in iPhone

时光总嘲笑我的痴心妄想 提交于 2020-01-17 08:06:09

问题


I have an NSMutable Array in FirstViewController class, I want to Pass that array to SecondViewController class. And I want to use that in SecondViewController class. I am doing this in Xcode 4.2.1 with ARC... How can I...? and what are the attributes i want to use when setting property... (OR) Explain me using Appdelegate files also...


回答1:


There are two ways to do this.

1: Make a property for NSMutableArray in appdelegate, set the value for array in FirstViewController and retrieve value in SecondViewController.

2: Make a property for NSMutableArray in SecondViewController, and call this property for FirstViewController but making the object of SecondViewController, and calling the property via object reference of secondViewController from FirstViewController.




回答2:


in current class

#import "SecondViewController"

 SecondViewController *NextViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];

        NextViewController.nextClasssArray = thisClassarray;

in second class .h

@property(nonatomic,retain) NSMutableArray *nextClasssArray;

in second class .m

@synthesize nextClasssArray;


来源:https://stackoverflow.com/questions/10242241/nsmutable-array-from-one-class-to-another-class-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!