开发者

Printing array of one view controller in another

Can we print an array that is declared in one view controller class in another?

If so how can 开发者_C百科we do it?

I had tried on it several ways by importing the view controller,used NSLog... but couldn't do so,please do help me.


If you want an array of class1 to print in class2, do these.

  1. Set array as a property of class1 and synthesize it.

  2. Make sure you allocate it and add data to it.

  3. Reference class1 in your class2 and create an object for class1.

    class1 *object1;
    
  4. object1.array should now point to that array.

Note:

You will need to NSLog quite often and check if the array does not become null when you move to a different view controller and make sure you allocate it properly. Also, if possible allocate that array in your AppDelegate and then using the delegate property, delegate.array you will definitely be able to access it.


One way of approaching it can be declare the delegate of the view controller from which u want to pass the array. Now include the delegate in the other view Controller and call its delegate function. Pass the array u want to print in its delegate function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜