I've been stuck with an issues for a couple of days and I think it's time to ask for help.
I have an UIView class "BonusObjects" which is set as delegate to ViewController.
I add some UIImageViews in this class, start moving them towards the edge of the screen with NSTimer and try to see if they intersect with an UIImageView from ViewController.m. I'm getting the coords of the target object as int and check if the X and Y of the images from BonusObjects are anywhere near the target.
Since the images from BonusObject have X=0, I have to convert their coords from the superview. Like that:
CGPoint newPoint = [[self superview]convertPoint:internal.center
fromView:[internal superview]];
bonusX= newPoint.x;
Here is the actual question: Why the delegate doesn't work in this if
statement:
if (padX < bonusX && bonusX < padX+40 && padY <= internal.frame.origin.y) {
[[self delegate] bonusEffect:internal.tag];
[internal removeFromSuperview];
internal=NULL;
}
But it works if I put it out of the if, or change bonusX to some random value that isn't taken from the superview.
Everything else in that if works fine - it removes the image, and displays the correct .tag value.
I can provide more code if needed.
EDIT: The delegate is (null)
in that if
, but outside of it it is <ViewController: 0xc03e600>
.
EDIT2: Here is how I set the delegate:
in BonusObjects.h
@protocol BonusDelegate
-(void)bonusEffect:(int)effect;
@end
@interface BonusObjects : UIView <UIApplicationDelegate> {
id <BonusDelegate> delegate;
} @property (nonatomic) id <BonusDelegate> delegate;
in ViewController.h:
#import "BonusObjects.h"
@interface ViewController : UIViewController <BonusDelegate, ADBannerViewDelegate> {
BonusObject *bonusView;
}
And in ViewController.m:
bonusView = [[BonusObjects alloc] init];
[bonusView setDelegate:self];