iphone - 使用 segue 传回数据时卡住

标签 iphone ios objective-c

我正在尝试使用协议(protocol)通过 segue 传回数据。我正在关注这个答案:How to Pass information Back in iOS when reversing a Segue?

所以我已经做了:

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>

//...

ContainerViewController.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”的对象上找不到属性“delegate”,但我确实将其添加为属性并合成了它...

最佳答案

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

试试这个:

替换

PageScrollViewController *secondViewController = segue.destinationViewController;

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

PageScrollViewController *secondViewController = segue.destinationViewController;

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

关于iphone - 使用 segue 传回数据时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16300492/

相关文章:

iphone - 泄漏已发布的NSString

iphone - postNotificationName : called 时未发送 NSNotification

iOS - NSDateFormatter dateFromString 仅在一种情况下返回 nil

ios - Uber native 登录标记错误

objective-c - 如何在 IOS 中心水平对齐我的图像

iphone - 对某些文本字段/ TextView 使用特殊的 iPad/iPhone 自动完成字典?

iphone - 核心动画 : ignoring exception: *** -[NSPlaceholderString initWithString:]: nil argument

objective-c - Objective C 中的 id 和 NSObject 有什么区别?

IOS/objective-C : Direct users to specific screen of app on clicking on notification

ios - 在基于ARC的APP中释放内存?