0

First of all, I am not Objective-c developer, however I have 4 years of experience in C and C++.

I am trying to make a few demo programs for an (iPad) app camp. For one of these programs I want to pass data between two UIViewControllers.

I have tried various examples, among the example below. Passing Data between View Controllers

The code is written in an older version of Xcode so I took a bit of tweaking to get it through the compiler. Now I am facing the following problems:

  • It seems the prepareForSegue is not being called when I open a new view? (Or am I doing something wrong?) I have tried various ways.

  • In the same post there is a way to pass a delegate to a new class and back to the calling class. When I run this all goes good but there is the last part:

In ViewControllerA.m implement the following method from our protocol

(void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
{
    NSLog(@"This was returned from ViewControllerB %@",item);
}

Does net execute... I have no idea what is wrong. I followed the example exactly. I can see the second view opening and closing, only the delegate code won't run. Do I have to do this in a different way in Xcode 7?

P.S. I know this is a basic question but I cant seem to find the answer or a good Xcode 7 guide anywhere.

Community
  • 1
  • 1
Tim
  • 1
  • Hi Tim, welcome! Passing data around an application, while fundamental, isn't really a "basic" thing. It gets into application architecture, data managers, and yes delegates, which are not beginner-level concepts. Can you explain how the segue is implemented in the tutorial? How did you verify that `prepareForSegue:sender:` isn't getting called? – markedwardmurray Jul 24 '16 at 19:01
  • Can you include the code for when you call `addItemViewController: didFinishEnteringItem:`? – michaelrccurtis Jul 24 '16 at 23:27

1 Answers1

0

following method from our protocol.. Does net execute...

Are you sure that you assign your first view controller's reference to your target view controller's delegate property like,

secondViewController.delegate = self;

You can do this in where you create the second view controller, e.g prepareForSegue method. If you forgot this your delegate method simply not work, because your second view controller doesn't know who's its delegate.

ergunemr
  • 1
  • 1
  • I create my secondviewcontroller with: [self] preformSegueWithIdentifier:@"AddContact" sender:self]; I guesed it would then automatically caal the prepareForSeque method?! What you say sounds logical but wont work when I use preformSequeWithIdentifier right? – Tim Jul 25 '16 at 20:11