0
  BookingDocumentsViewController *bdVc = [self.storyboard instantiateViewControllerWithIdentifier:@"BookingDocs"];
    bdVc.orId = rl_id;
    bdVc.docsArray =  self.documentsArray;
    [self.navigationController pushViewController:bdVc animated:YES];

I have Above code snippet. I'm trying to load a new viewcontroller and assign its Mutable Array (docsArray) object to current view's mutableArray (documentsArray <=this is not nil)

Whenever I execute above code I get EXC_BAD_ACCESS error.

but if I comment the 3rd line. It works but I can't get my array to the new view. I even tried with [[NSMutableArray alloc] initWithArray:self.documentsArray]; this doesnt work either.

But if I use bdVc.docsArray =[[[NSMutableArray alloc] init]; it works but again I can't get my mutable array to the new view.

Edit: However 2nd line has NSString values. And they can be passed without a problem.

What am I doing wrong here?

I'm not getting any errors in console, instead I get this.

enter image description here

6
  • Post the stacktrace of the crash. Commented Nov 12, 2012 at 11:53
  • 1
    Are you doing something with docsArray in bdVc's viewDidLoad or viewWillAppear/viewDidAppear? Is docsArray a strong property? Commented Nov 12, 2012 at 11:53
  • yes docsArray is a strong property. And I'm not doing anything with docsArray in anywhere else. Commented Nov 12, 2012 at 11:57
  • As you've already been asked - Stack trace please. Commented Nov 12, 2012 at 12:06
  • No errors in console, app crashes.I updated the question. Commented Nov 12, 2012 at 12:11

3 Answers 3

2

Maybe consider using a Segue. It instantiates the destination viewcontroller for you. Then in your source view controller implement

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

Get a reference to your destination viewcontroller and set its data.

BookingDocumentsViewController *bdVc = [segue destinationViewController];
bdVc.docsArray = self.documentsArray;
Sign up to request clarification or add additional context in comments.

Comments

0

in BookingDocumentsViewController.h

@property(nonatomic, retain)NSmutableArray *docsArray;

You do can do in your BookingDocumentsViewController.m:

@synthesize docsArray;

- (void)viewDidLoad
 {
    NSmutableArray *array = [NSmutableArray alloc]initWithArray:docsArray];   
   [super viewDidLoad];
 }

then when you are pushing the view

BookingDocumentsViewController *bdVc = [self.storyboard instantiateViewControllerWithIdentifier:@"BookingDocs"];
bdVc.orId = rl_id;
bdVc.docsArray =  self.documentsArray;
[self.navigationController pushViewController:bdVc animated:YES];
[bdVc Release];

2 Comments

what is the point of creating a local array in viewDidLoad that isn't used anywhere? This is nowhere near an answer
well you can define that array in .h if you want to use it in other blocks i was just focusing on passing the array value funda...anyway will take care of that in future.
0

I think I found the issue. A very basic mistake. In bdVc's viewDidLoad I had the following line,

NSLog(@"Booking Documents viewDidLoad : %@",self.docsArray.count);

This was causing the error. that %@ instead of %d. I wonder why xcode didn't show proper reason for the error.

Thank you all for the help. :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.