Shivbaba's son
Shivbaba's son

Reputation: 1369

Problem calling custom delegate method on iOS

In my iPhone application...

Could not call the delegate method ...

Here is my code

I have created a simple delegate in one class...

@protocol imagecelldelegate

-(BOOL) isIntersects:(CGRect)lastTouch;

@end

@interface ImageDemoGridViewCell : AQGridViewCell
{
    id<imagecelldelegate> delegate; 
}

@property (nonatomic,retain) id delegate;

@end

Now I have set the delegate in this class's implementation and called the delegate method.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self setDelegate:self.superview];

    [delegate isIntersects:originalSelf];
     //Getting error at this point...   

}

After that I have implemented the method in the class which I have set the delegate..

@interface ViewController : UIViewController<imagecelldelegate>
{

And implemented the method in this class....

-(BOOL) isIntersects:(CGRect)lastTouch
{

    NSLog(@"Delegate Yippee");

    return YES;
}

Upvotes: 1

Views: 634

Answers (1)

Ilanchezhian
Ilanchezhian

Reputation: 17478

[self setDelegate:self.superview];

This is the problem.

You should set the ViewController as the reference for the delegate.

For example, after you have allocated the ImageDemoGridViewCell in ViewController, set the delegate as follows.

ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..];
cell.delegate = self;

Then add the cell as subview to the ViewControllers view.

Upvotes: 5

Related Questions