simple function call not working
HI guys,
such a newbie at objective c in general, i am trying to implement a simple function
in my .h file i have declared the function as so:
have described what i wish to do when the function is called as so:
and when i wish this to happen:
is done like so:
and i get compile errors such as
implicit decleration of throwBall;
property throwBall requires method -ballThrown to be defined - use @synthesise etc
im sorry for posing what i believe to be such a simple thing to do ( is in other languages that im quite competent at) but until i get my head around function decleration i can press on with my final year project - yes due in 3 weeks!
have read reems of google stuff but to no avail.
any help please - much appreciated
such a newbie at objective c in general, i am trying to implement a simple function
in my .h file i have declared the function as so:
Quote:- (void) throwBall;
have described what i wish to do when the function is called as so:
Quote:-(void) throwBall
{
//do this etc
}
and when i wish this to happen:
is done like so:
Quote:- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
CGFloat deltaX = fabsf(gestureStartPoint.x - location.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - location.y);
if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
player1.text = @"Vertical swipe"; //debug to check for vertical swipe of any kind based on the boundaries at top
//implement ball move on y!
throwBall(); // HERE IS THE FUNCTION CALL!!!
}
}
and i get compile errors such as
implicit decleration of throwBall;
property throwBall requires method -ballThrown to be defined - use @synthesise etc
im sorry for posing what i believe to be such a simple thing to do ( is in other languages that im quite competent at) but until i get my head around function decleration i can press on with my final year project - yes due in 3 weeks!
have read reems of google stuff but to no avail.
any help please - much appreciated
Because what you have declared is not a function - it is a method - and should be called using:
The function equivalent to that method would be declared as:
Code:
[ [i]<object>[/i] throwBall ];Code:
void throwBall( void );Mark Bishop
As sealfin said; to call class method in objective-c you use the syntex
[ OBJECT_NAME_HERE METHOD_NAME_HERE]
so if you are calling your throwBall method in the same class that you defined it you could call it like so:
[self throwBall];
I.E.
Now lets say you create an object of ClassName in some other class you create. In that case you would call throw ball like this:
I hope that helps.
[ OBJECT_NAME_HERE METHOD_NAME_HERE]
so if you are calling your throwBall method in the same class that you defined it you could call it like so:
[self throwBall];
I.E.
Code:
-ClassName.h-
@interface ClassName : NSObject {
}
-(void) throwBall;
@end
-ClassName.m
@implementation ClassName
-(id)init
{
if(!(self = [super init])) return nil;
// Lets throw the ball.
[self throwBall];
}
-(void) throwBall
{
// Do stuff here
}
@endNow lets say you create an object of ClassName in some other class you create. In that case you would call throw ball like this:
Code:
ClassName *myClassNameObject = [[ClassName alloc] init];
[myClassNameObject throwBall];I hope that helps.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Objective-C message call efficiency | Blacktiger | 10 | 4,431 |
Aug 20, 2006 03:37 AM Last Post: OneSadCookie |
|

