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...
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With