【发布时间】:2012-05-24 18:34:01
【问题描述】:
我从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;
正如有人在答案中所写,但仍然无法正常工作。
请帮帮我。
【问题讨论】:
-
您是否确保包含
PageControlDelegate协议的实际声明,而不仅仅是前向声明?您必须向下滚动第一个代码块才能看到实际的声明,因此您可能只是错过了它。 -
这不是错误,这是警告。由于 Objective-C 的动态行为,编译器实际上无法在编译时告诉指定的选择器是否要响应,因此在这种情况下它不会终止编译。
-
@DanF 在我拥有的 .h 文件中:在协议 PageControlDelegate; .
-
@H2CO3 它确实终止了编译。
-
您正在使用 -Werr 进行编译?使用默认设置,它不应该终止它。
标签: iphone objective-c ios macos delegates