i tried to implement this code that move UIImageView’s objects,
i get a compiler warning for the objects (jumpBall1…) in the createPosition method: UIImageView may not respont to -setupperLimit, -setlowerLimit, -setspeed
code:
@interface JumpBallClass : UIViewController
{
CGPoint center;
CGPoint speed;
CGPoint lowerLimit;
CGPoint upperLimit;
IBOutlet UIImageView *jumpBall1;
IBOutlet UIImageView *jumpBall2;
}
@property (assign) CGPoint lowerLimit;
@property (assign) CGPoint upperLimit;
@property (assign) CGPoint speed;
@property(nonatomic,retain) IBOutlet UIImageView *jumpBall1;
@property(nonatomic,retain) IBOutlet UIImageView *jumpBall2;
- (void)update;
@end
@implementation JumpBallClass
- (void)update
{
center.x += speed.x;
center.y += speed.y;
if (center.x > upperLimit.x || center.x < lowerLimit.x)
{ speed.x = -speed.x; }
if (center.y > upperLimit.y || center.y < lowerLimit.y)
{ speed.y = -speed.y; }
}
@end
- (void) jumpOnTimer {
NSArray * balls = [NSArray arrayWithObjects:jumpBall1, jumpBall2, nil];
[balls makeObjectsPerformSelector:@selector(update)];
}
- (void) createPosition {
[jumpBall1 setUpperLimit:CGPointMake(60, 211)];
[jumpBall1 setLowerLimit:CGPointMake(0, 82)];
[jumpBall1 setspeed:CGPointMake(2.0,7.0)];
...
}
Your code is attempting to call the methods setUpperLimit: setLowerLimit: and setspeed: on the member variable jumpBall1 which you have declared as a UIImageView. However these are not methods of UIImageView – they are setter methods on the @properties you have declared in your own custom JumpBallClass. You have not specified the synthesis of these properties in your implementation file however (using the @synthesize keyword).
Perhaps what you mean to do is make the JumpBallClass a subclass of UIImageView and instantiate two instances of this, one for each jumpBall which you would like to control.