3

I'm trying to pass data back with the segue using protocols. I'm following this answer: How to Pass information Back in iOS when reversing a Segue?

So what I already did:

PageScrollViewController.h

@protocol MyDataDelegate <NSObject, UIPageViewControllerDelegate>

- (void)recieveData:(NSString *)theData;

@end

and I also added the property:

@property (nonatomic,weak) id<MyDataDelegate> delegate;

ContainerViewController.h

#import "PageScrollViewController.h"

@interface ContainerViewController : UIViewController <MyDataDelegate>

//...

ContainerViewController.m

- (void)recieveData:(NSString *)theData {

    //Do something with data here
}

and here I'm stuck:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    //Get a handle on the view controller about be presented
    PageScrollViewController *secondViewController = segue.destinationViewController;

    if ([PageScrollViewController isKindOfClass:[PageScrollViewController class]]) {
        PageScrollViewController.delegate = self;
    }
}

The line PageScrollViewController.delegate = self; gives an error: Property 'delegate' not found on object of type 'PageScrollViewController' but I did add it as a property and synthesized it...

Community
  • 1
  • 1
nonuma
  • 399
  • 1
  • 3
  • 14

1 Answers1

5

You're trying to call an instance method ([PageScrollViewController setDelegate:]) on an object of type Class (in this case, PageScrollViewController).

Try this:

Replace

PageScrollViewController *secondViewController = segue.destinationViewController;

  if ([PageScrollViewController isKindOfClass:[PageScrollViewController class]]) {
    PageScrollViewController.delegate = self;
  }

With

PageScrollViewController *secondViewController = segue.destinationViewController;

  if ([secondViewController isKindOfClass:[PageScrollViewController class]]) {
    secondViewController.delegate = self;
  }
sam-w
  • 7,478
  • 1
  • 47
  • 77