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

2
  • show the code where you are trying to pass the array. Commented Jul 4, 2014 at 18:07
  • possible duplicate of Passing Data between View Controllers Commented Jul 5, 2014 at 0:07

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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];
Note that the OP isn't passing an NSArray. An int[] isn't an object, so standard property attributes do not apply.
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

1 Comment

Note that the OP isn't passing an NSArray.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.