2012-05-24 122 views
2

我從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; 

有人在答案中寫道,但仍然無法正常工作。

請幫幫我。

+0

你一定要包括'PageControlDelegate'協議的實際申報,而不是隻是前瞻性聲明?您必須向下滾動第一個代碼塊才能看到實際的聲明,因此您可能錯過了它。 –

+0

這不是一個錯誤,這是一個警告。由於Objective-C的動態行爲,編譯器實際上無法在編譯時告訴指定的選擇器是否被響應,所以在這種情況下它不會終止編譯。 – 2012-05-24 18:38:29

+0

@DanF在.h文件中我有:at protocol PageControlDelegate; 。 –

回答

4

如果你的頭,你只需要:

@protocol PageControlDelegate; 

你錯過的協議是什麼,實際的定義。在你的鏈接後,首先代碼塊的底部有這個代碼包含遺漏協議函數的聲明:

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

oops:\我沒有看到那..對不起,謝謝! –

0

您需要導入聲明PageControlDelegate協議的.h文件。

+0

它聲明瞭PageControlDelegate協議! :( –

相關問題