simple function call not working

burrows111
Unregistered
 
Post: #1
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:
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
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #2
Because what you have declared is not a function - it is a method - and should be called using:
Code:
[ [i]<object>[/i] throwBall ];
The function equivalent to that method would be declared as:
Code:
void throwBall( void );

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.04
Post: #3
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.
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
}

@end

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:
Code:
ClassName *myClassNameObject = [[ClassName alloc] init];
[myClassNameObject throwBall];

I hope that helps.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Objective-C message call efficiency Blacktiger 10 5,074 Aug 20, 2006 03:37 AM
Last Post: OneSadCookie