我从 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/