0

I'm passing a string variable for the sake of testing (isLoggedIn) as well as an NSManagedObject (userObject). However, when I dismiss the VC and it comes back to the root, I do not have the new data that was set in the variables in the loginViewController.

LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
loginVC.managedObjectContext = self.managedObjectContext;
loginVC.userObject = self.userObject;
loginVC.isLoggedIn = self.isLoggedIn;

[self presentModalViewController:loginVC animated:YES];
[loginVC release];

I later dismiss the view with:

[self dismissModalViewControllerAnimated:YES];

Update:

Ended up using delegates as someone suggested. I used the following post as a guideline:

UIViewController parentViewController access properties

Community
  • 1
  • 1
Marcin
  • 1,266
  • 3
  • 15
  • 31
  • 4
    I believe you need to use delegate for this. – user523234 Nov 22 '11 at 21:34
  • Can you explain a little more about what data you're talking about? You're using a correct way of showing the view controller in a modal way, but I'd add a delegate field in the LoginViewController class and set that to the calling class. Also, if you're making changes in Core Data, don't forget to save them with a context save call! – RDM Nov 22 '11 at 21:48

2 Answers2

1

I ended up using delegates as someone above suggested. I used the following post as a guideline:

UIViewController parentViewController access properties

Community
  • 1
  • 1
Marcin
  • 1,266
  • 3
  • 15
  • 31
0

I may not be following you properly so this could be irrelevant.

I am guessing you mean that:

  1. You set your ivars after alloc/init
  2. You make some changes inside LoginViewController
  3. You expect those changes to be reflected in self.userObject and self.isLoggedIn of the class that instantiated LoginViewController

which may or may not happen if you act on the objects themselves or you reassign the pointers

e.g.

If you call self.userObject.name = @"Test"; inside LoginViewController then the change will be reflected in the class that instantiated LoginViewController and LoginViewController because the ivars are pointing to the same object in memory and you are manipulating the object.

OR

If you call self.userObject = theResultOfSomeNewFetch; then the change will not be reflected as you now have a pointer in LoginViewController that is pointing to a different userObject to the pointer in the class that called LoginViewController

Hopefully I have not lost the plot completely and this is somewhere near what you mean.

Paul.s
  • 38,494
  • 5
  • 70
  • 88
  • Yeah this is my thought exactly. If you say stringA=stringB and then say stringB=@"my new string" stringB will be assigned a new pointer so stringA will no longer be pointing to stringB, so you won't see the new value reflected. If you used a mutable string for example then you can change the value of stringB without allocing a new string and therefore assigning it a new pointer. – nebs Nov 22 '11 at 23:01