user1452248
user1452248

Reputation: 767

Expected expression missing in If else else if statements

I am trying to solve my other question. So i thought maybe with if else if else statement can solve my problem.

But i think i m missing expected expression in below if else else if statement.

-(void)playpauseAction:(id)sender 
{
    if ([audioPlayer isPlaying]){       
            [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
        [audioPlayer pause];
        [self pauseTimer];
    } else {
        [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        [audioPlayer play];
        [self resumeTimer];
    }  
    else if
    {
        [audioPlayer play];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                        target:self
                                        selector:@selector(displayviewsAction:)
                                        userInfo:nil
                                        repeats:NO];
    }    
}

Any idea what i m doing wrong over here.

Thanks.

Upvotes: 0

Views: 274

Answers (3)

Abhishek
Abhishek

Reputation: 2253

use it in this way

-(void)playpauseAction:(id)sender 
{
     if([audioPlayer isPlaying]){       
       [sender setImage:[UIImage imageNamed:@"Play Icon.png"]          forState:UIControlStateSelected];
      [audioPlayer pause];
      [self pauseTimer];
} 
else if(put your condition here)
{
    [audioPlayer play];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                    target:self
                                    selector:@selector(displayviewsAction:)
                                    userInfo:nil
                                    repeats:NO];
}   
else {
    [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [audioPlayer play];
    [self resumeTimer];
    }   
}

hope this will help you..

Upvotes: 1

Gabriel Baker
Gabriel Baker

Reputation: 1219

How can you have if ... else ... elseif?

Is your code not just in the wrong order? Pretty sure you can't have an elseif of an else.

if elseif else?

Upvotes: 0

Dan F
Dan F

Reputation: 17732

You need to have the else if before the else block. And else if is a secondary conditional, it requires some kind of boolean statement following it like a normal if, such as ![audioPlayer isPlaying]. I'm not sure what you're trying to achieve with your code, so I can't provide any more advice beyond that.

Upvotes: 1

Related Questions