0

I have an NSMutableArray array1 in aUIViewController. The values in array1 are generated dyanamically. Now when i Switch to my UITableViewController I need to retrieve those array1 values here in this table. Any basic method how to copy an array to the UITableViewController?

Stephen Melvin
  • 3,696
  • 2
  • 27
  • 40

1 Answers1

0

Give the table view controller a NSMutableArray property:

@property (nonatomic, strong) NSMutableArray *array1;

Prepare for the segue programmatically, and its easy enough to pass the object like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
     if ([segue.identifier isEqualToString:@"showTableView"]) {
         ViewController *destViewController = segue.destinationViewController;
         destViewController.array1 = array1;
     }
}

Clearly, some of the text in the example needs to be changed to match your segue identifier and or variables, but that should do what you need.

William Riley
  • 878
  • 8
  • 13
  • yeah William, it worked absolutely., thanks for that. I have one more question for you.Whenever we need to Copy values between viewcontrollers., can we use the same method ? – rdraviteja Mar 06 '14 at 08:29
  • Should always work out fine. As long as the destination VC has the property, it can be set in the prepareForSegue method. Happy coding. – William Riley Mar 06 '14 at 14:04