0

I have an in integer array that I'd like to pass from one view controller to another.

I can pass strings from one view to a label in another however I'm not able to do that with an int array.

Basically I have declared the following in viewController_A: -

int totalArray[30];

and I want to pass it to viewController_B

Till
  • 27,559
  • 13
  • 88
  • 122
thefan12345
  • 136
  • 16
  • show the code where you are trying to pass the array. – rishi Jul 04 '14 at 18:07
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Hot Licks Jul 05 '14 at 00:07

3 Answers3

3

There shouldn't be any difference between passing an integer array and a string from one ViewController to another.

Sending data between ViewControllers is relatively simple, Here's a link to something I found useful when I first sent data between ViewControllers. Passing Data between View Controllers

Make sure your array declaration is strong:

@property (nonatomic, strong)NSMutableArray *exampleArray;

Edit: Trying to pass an integer array would be a lot more work than holding your values inside an NSMutableArray or NSArray since you cannot declare a c-style array as a property without a work-around as can seen in this post Create an array of integers property in Objective C

If you look at robottobor's answer on that link you will see how you can implement the array as a property, but again I strongly suggest you use an NSMutableArray or NSArray.

Community
  • 1
  • 1
MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
  • I wrote the following but it doesn't work. Do I have to use a NSMutableArray... I just want to pass an integer array. @property (strong, nonatomic)int *testArray[30]; – thefan12345 Jul 04 '14 at 23:42
  • Note that the OP isn't passing an NSArray. An `int[]` isn't an object, so standard property attributes do not apply. – Hot Licks Jul 05 '14 at 00:09
0

Just make a property in the receiving view controller: @property(nonatomic, strong) NSArray *array

Then in prepareForSegue just access that property destViewController.array = intArray

mginn
  • 16,036
  • 4
  • 26
  • 54
0

Here, I describe easy way to pass array between two controller.

Suppose you want two pass array from controller1 to controller2.

  1. create array in controller2.
  2. import controller2 file in controller1.
  3. create object of controller2 file.

Code:

controller2 *cn2 = (controller2 *)[self.storyboard instantiateViewControllerWithIdentifier:@"storyboard_identifier"]; // create object of second controller

    cn2.array_name = array_name; //pass first controller array to second controller

[self.navigationController pushViewController:cn2 animated:YES]; // redirect to second controller

Thank You.

Gangani Roshan
  • 583
  • 1
  • 8
  • 25