0

I am currently in the process of switching from Android to the iPhone SDK. I have a TableView where the user selects an item. I am having trouble passing data between controllers. Is there an equivalent to the Android's startActivityForResult or putting extra's into Intents? Like so ...

Intent i = new Intent(this, Foo.class);
i.putExtra("Foo", foo);
Stefan Bossbaly
  • 6,682
  • 9
  • 53
  • 82
  • 2
    This has been asked several times. http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Joe Jul 11 '11 at 15:08
  • It's as simple as passing data between objects. Just do it ✔ – David Snabel-Caunt Jul 11 '11 at 15:14
  • The big problem I am having is that the user can select alot of options on this view (UISwitch, Buttons etc) but every time i launch a new controller to try to get a selection from the user and i report back all of the UI components are reset. – Stefan Bossbaly Jul 11 '11 at 15:22

1 Answers1

1

Take this in .h file in ParentViewController

NSString *strABC;

Make below function in ParentViewController

-(void)setString:(NSString *)strEntered{
    strABC=strEntered;
}

Now In Post view controller do like this:

ParentViewController *objSecond = [[ParentViewController] initwithNibName:@"parentView.xib" bundle:nil];

[objSecond setString:@"Comment Controller"];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];

Now, In secondViewController viewWillAppear Method write this.

-(void)viewWillAppear:(BOOL)animated{
      lblUserInput.text = strABC;
}

Please check spelling mistakes as I hand written this. Hope this help.

If you are not using navigationContoller then you can do something like this.

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setUserInput:txtUserInput.text];
[objSecond viewWillAppear:YES];
[self.view addSubview:objSecond];
[objSecond release];
Deeps
  • 4,399
  • 1
  • 26
  • 27