-1

How to pass data from a UIiewcontroller to a uitableview grouped in another viewcontroller. ( And Vice Versa)

Any example's and tutorials of this would be deeply appreciated. I have tried use if statements from strings set from across Viewcontrollers using retain @property and then set as the text from UILabel's. I doens't work.

  • Look into protocols and delegates to keep communication decoupled between them. http://stackoverflow.com/questions/7215698/what-exactly-does-delegate-do-in-xcode-ios-project/7215969#7215969 – bryanmac Mar 01 '13 at 22:54
  • also - http://stackoverflow.com/questions/8262997/delegates-vs-events-in-cocoa-touch/8263516#8263516 good luck – bryanmac Mar 01 '13 at 22:54
  • If you need help with a specific problem you are having, please make sure to post code to serve as an example of the problem. Writing your question so as to let others know exactly what is going wrong, and also making sure you've thoroughly researched what other people have tried, will help you solve your problem faster and get a good response to your questions here. Best of luck! – Carl Veazey Mar 01 '13 at 22:58
  • Passing Data from a VC to another XCode or another class(VC) ?? Do you really want to pas to XCode or your requirement may get change to pass to Finder, iTunes, Safari etc? – Anoop Vaidya Mar 02 '13 at 02:36

1 Answers1

1

I do not know how to do the vice-versa part but use this for transferring data to another view controller: (I am going to pretend that I want to pass a string named "hello" to the second view controller)

(I will now call the First View Controller FirstVC, and I'll call the second view controller SecondVC)

  1. In storybord, click on segue and in the utilities section open Attributes and look for the identifier box

Attributes Segue

, and enter "Segue"

2.In the second view controller.h file, declare a property and synthesize it(in both FirstViewController, and Second):

@property (nonatomic, retain) NSString *hello;

3.In the FirstViewCOntroller add this code:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender identifiers:(NSArray *)identifiers {
    if ([segue.identifier isEqualToString:@"Segue"]) {
         SecondViewController *secondVC = [segue destinationViewController];
         secondVC.hello = self.hello;
    }
} 
DHShah01
  • 553
  • 1
  • 7
  • 16
  • This creates tight coupling between your views which is very non-MVC. The point of MVC is for the view code to not be coupled and drive off the model through the controller. Either use notifications or a protocol to decouple. – bryanmac Mar 02 '13 at 00:04