开发者

How to access/print an NSMutableArray element from one view to another view?

I have an NSMutableArray named mArray in view1 and it stores some strings. Now I开发者_运维百科 want to access/print/compare these elements in view2. Please guide me.


write property synthesize for marray in view1 class.Then create view1 object in the view2 and use as view1object.marray


Suggestion:

You could put the array in your Controller class,where they both could access.

It is always better to have sharable data in Controller then views if data has to be shared among views.


view1.mArray should do it.

Pls note to @synthesize the mArray in view1. To print the array in console

NSLog(@"mArray from view 1 is %@",view1.mArray);


If view2 is presented pushed whatever in view1, then you can pass it down as a property from view1.

If both are on the same level, spawned by a super view controller, own the array in a property of the super controller and pass it down to the views.

You can also implement a singleton and share the model as a single instance, accessed directly in the views.


I suggest that your views situated in different ViewControllers. There are several kinds:

  1. Create a property for your target viewcontroller and set your array after creating VC instance.
  2. Make -(id)initWithArray:(NSMutableArray*)array; method for your viewcontroller
  3. Use singleton for your whole project,
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜