iphone - 'NSObject<PageControlDelegate>' 没有可见的@interface 声明选择器 'pageControlPageDidChange:'

标签 iphone objective-c ios macos delegates

我从 this post 得到了这段代码一切正常,除了一件事,我有这个错误,我不知道如何修复。这是代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    CGPoint touchPoint = [[[event touchesForView:self] anyObject] locationInView:self];

    CGRect currentBounds = self.bounds;
    CGFloat x = touchPoint.x - CGRectGetMidX(currentBounds);

    if(x<0 && self.currentPage>=0){
        self.currentPage--;
        [self.delegate pageControlPageDidChange:self]; 
    }
    else if(x>0 && self.currentPage<self.numberOfPages-1){
        self.currentPage++;
        [self.delegate pageControlPageDidChange:self]; 
    }   
}

错误是:

No visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'.

我尝试用 ARC 运行这段代码,我删除了 dealloc 方法,在这里将 assign 更改为 weak:

@property (nonatomic, weak) NSObject<PageControlDelegate> *delegate;

正如有人在答案中所写的那样,但它仍然无法正常工作。

请帮帮我。

最佳答案

如果在您的 header 中,您只有:

@protocol PageControlDelegate;

您错过了协议(protocol)的实际定义。在您链接的帖子的第一个代码块的底部,有这段代码包含缺少的协议(protocol)函数的声明:

@protocol PageControlDelegate<NSObject>
@optional
- (void)pageControlPageDidChange:(PageControl *)pageControl;
@end

关于iphone - 'NSObject<PageControlDelegate>' 没有可见的@interface 声明选择器 'pageControlPageDidChange:',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10743301/

相关文章:

iphone - 将 NSData 包含在不同的核心数据实体中会使原始实体的检索更快吗?

objective-c - 设置值 :forUndefinedKey: this class is not key value coding-compliant for the key

ios - UITabbar 在 iOS 10 中拉伸(stretch)但在 11+ 中不拉伸(stretch)

ios - Ember Cordova 应用程序在 iOS 11.3 中卡在加载屏幕上

iphone - 帮助生成 ical ics 文件

ios - Cocos2d - iPhone eclipse 效果

iphone - 在 iOS 上制作老虎机

ios - 如何使用 "sequential finger detection"的新 iOS 9.2 Touch ID 功能

ios - 如何检测来自另一个类的 touchesBegan、touchesMoved、touchesEnded 事件

ios - 为什么在枚举和切换时需要强制解包?