0

I have 3 view controllers

The first view controller is storing objects in an NSMutableArray from text fields, info entered by user. There are 4 fields which are being stored as one object in an NsMutableArray.

After storing the data in the array, it is then being stored in another array, array2, which is located in the 2nd view controller, the 2nd view controller has a UItableview and custom tableview cell. The array2 is displaying the information in the tableview cell.

I have an update btn which goes to the 3rd view controller and displays all the information in the tableview cell in 4 uitextfields just like in the 1st view controller. After I change the data, I am storing it again in another array, array3 which I want to pass back to the previous 2nd view controller to display the updated info in the table view cell.

Everything is working fine up till now, my question is, how can I pass the array3 back to the previous view controller to show the updated info? I am using delegates to pass data but I cannot seem to pass it back to the previous view controller. the app crashes and the error is "object cannot be nil"

I have checked various tutorials and questions but cannot find the answer. Please help.

Using delegates and arrays

  • You need to show your code. At least the method in the 3rd view controller where you pass the data back to the 2nd view controller, and the implementation of the delegate method in the 2nd controller. Also, point out which line gives the error. – rdelmar Jan 17 '15 at 05:58
  • Declare an object in AppDelegate and then You can store your data in that object. So that object will be accessible from the whole application as it is inside the Application Delegate. – Kanan Vora Jan 17 '15 at 06:03
  • If you see "object" cannot be nil. That's pretty straightforward. Go back to check your code instead. – Lucas Huang Jan 17 '15 at 06:19
  • Can't really help you unless you show you code. – Senõr Ganso Jan 17 '15 at 06:28
  • Code is more intuitive than reading the whole passage like this. – Lucas Huang Jan 17 '15 at 08:10
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Hot Licks Jan 17 '15 at 13:28

2 Answers2

1

You have to pass array in your delegate method so you can get this array in second viewcontroller. For example you have called delegate method like : [self.delegate setData:(NSMutableArray *)array];

You can get this array where you define setData method like

  • (void)setData:(NSMutableArray *)array { NSLog(@"Array value %@",array) }
Shivani Gor
  • 329
  • 1
  • 8
0

My suggestion is you can maintain your NSMutableArray in Appdelgate OR Using the NSUserdefaults

-By using these you can maintain your data anywhare in the project