3

I've got this code from this post and everything is ok except one thing, I have this error that I dont know how to fix. this is the code:

- (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]; 
    }   
}

the error is that:

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

I've tried to run this code with ARC, I removed the dealloc method, changed assign to weak in here:

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

as someone wrote in the answers, but still it isn't working.

Please help me.

Community
  • 1
  • 1
ytpm
  • 4,962
  • 6
  • 56
  • 113
  • 1
    Did you make sure to include the actual declaration of the `PageControlDelegate` protocol, and not just the forward declaration? You have to scroll down the first code block to see the actual declaration, so it is possible you just missed it. – Dan F May 24 '12 at 18:38
  • This is not an error, this is a warning. Due to Objective-C's dynamic behavior the compiler is actually incapable of telling at compile time whether the specified selector is to be responded to, so it doesn't terminate the compilation in this case. –  May 24 '12 at 18:38
  • @DanF on the .h file I have: at protocol PageControlDelegate; . – ytpm May 24 '12 at 18:49
  • @H2CO3 it does terminate the compilation. – ytpm May 24 '12 at 18:49
  • You're compiling with -Werr? Using the default settings, it should NOT terminate it. –  May 24 '12 at 18:58

2 Answers2

5

If in your header you just have:

@protocol PageControlDelegate;

You missed the actual definition of what the protocol is. At the bottom of that first code block in your linked post there is this code that contains the declaration of the missing protocol function:

@protocol PageControlDelegate<NSObject>
@optional
- (void)pageControlPageDidChange:(PageControl *)pageControl;
@end
Dan F
  • 17,654
  • 5
  • 72
  • 110
0

You need to import the .h file that declares the PageControlDelegate protocol.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57