Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck when passing data back with segue

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...

like image 763
nonuma Avatar asked Jan 18 '26 05:01

nonuma


1 Answers

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;
  }
like image 81
sam-w Avatar answered Jan 19 '26 20:01

sam-w



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!