Reputation: 1369
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
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 ViewController
s view.
Upvotes: 5