manuelBetancurt
manuelBetancurt

Reputation: 16138

Calling simple method in if-statement

I'm still getting the objective c way, have done some progress, but I'm stuck in some stupid dilemma:

I need to call a method in an if,

if([title isEqualToString:@"Button 1"])
{
  [self mensage1];
}

the method

void mensage1() 
{
    NSLog(@"Button 1 was selected.");
}

also I declared in *.h

-(void) mensage1;

Obviously is not working well. Please tell me what I'm doing wrong...

Upvotes: 0

Views: 559

Answers (4)

manuelBetancurt
manuelBetancurt

Reputation: 16138

Well , this is not the answer, just the continuation of the question,,, if I do

void mensage1 
{
NSLog(@"Button 1 was selected.");
}

I get an error> Expected = , ; asm or attribute before { token

also , si the call to the function ok in the if?? [self mensage1]; ??

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163258

Your method definition is wrong, but your declaration is correct, simply copy it to your implementation file and strip the semicolon:

- (void) mensage1
{
   NSLog(@"Button 1 was selected.");
}

What you defined in your .m file is a C function, not an Objective-C method.

Upvotes: 2

Shaggy Frog
Shaggy Frog

Reputation: 27601

You declared an Objective-C method but you defined a C function.

What you want is:

- (void)mensage1
{
    NSLog(@"Button 1 was selected.");
}

Upvotes: 1

kiblee
kiblee

Reputation: 33

It's extremely hard to understand what you're trying to ask. First of all, how exactly is it not working?

Is the if statement not working? Or is the mensage1() method not being called?

Upvotes: 0

Related Questions