3

我正在尝试使用协议将数据与 segue 一起传回。我正在关注这个答案:如何在反转 Segue 时将信息传回 iOS?

所以我已经做了:

PageScrollViewController.h

@protocol MyDataDelegate <NSObject, UIPageViewControllerDelegate>

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

@end

我还添加了属性:

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

ContainerViewController.h

#import "PageScrollViewController.h"

@interface ContainerViewController : UIViewController <MyDataDelegate>

//...

容器视图控制器.m

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

    //Do something with data here
}

在这里我被困住了:

- (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;
    }
}

该行 PageScrollViewController.delegate = self;给出了一个错误:在“PageScrollViewController”类型的对象上找不到属性“委托”,但我确实将它添加为属性并合成了它......

4

1 回答 1

5

您正在尝试在类型(在本例中为 )的对象上调用实例方法( )。[PageScrollViewController setDelegate:]ClassPageScrollViewController

试试这个:

代替

PageScrollViewController *secondViewController = segue.destinationViewController;

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

PageScrollViewController *secondViewController = segue.destinationViewController;

  if ([secondViewController isKindOfClass:[PageScrollViewController class]]) {
    secondViewController.delegate = self;
  }
于 2013-04-30T13:05:42.173 回答