我從this post得到了這段代碼,除了一件事之外,一切都正常,我有這個錯誤,我不知道如何解決。這是代碼:'NSObject <PageControlDelegate>'沒有可見的@interface聲明選擇器'pageControlPageDidChange:'
- (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方法,改變分配到薄弱的位置:
@property (nonatomic, weak) NSObject<PageControlDelegate> *delegate;
有人在答案中寫道,但仍然無法正常工作。
請幫幫我。
你一定要包括'PageControlDelegate'協議的實際申報,而不是隻是前瞻性聲明?您必須向下滾動第一個代碼塊才能看到實際的聲明,因此您可能錯過了它。 –
這不是一個錯誤,這是一個警告。由於Objective-C的動態行爲,編譯器實際上無法在編譯時告訴指定的選擇器是否被響應,所以在這種情況下它不會終止編譯。 – 2012-05-24 18:38:29
@DanF在.h文件中我有:at protocol PageControlDelegate; 。 –