Expected Expression Error


#1

I went to run the code and it came up with an “expected error expression” on the line with the code “(IBAction)showQuestion: (id)sender.” I went through the code in the book and still can’t find what I’m doing wrong. A little help please.

[code]#import “QuizViewController.h”

@interface QuizViewController ()

@end

@implementation QuizViewController

  • (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    // Call the init method implemented by the superclass

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    // Create two arrays and makes the pointers point to them

      questions = [[NSMutableArray alloc] init];
      answers =  [[NSMutableArray alloc] init];
      
      // Add questions and answers to the arrays
      [questions addObject:@"What is 7+7?"];
      [answers addObject:@"14"];
      [questions addObject:@"What is the capital of Vermont?"];
      [answers addObject:@"Montpelier"];
      [questions addObject:@"From what is cognac made?"];
      [answers addObject:@"Grapers"];
    

    }
    // Return the address of the new object return self;

  • (IBAction)showQuestion:(id)sender
    {
    // Step to the next question
    currentQuestionIndex++;

      //Am I past the last question?
      if (currentQuestionIndex == [questions count])
      // Go back to the first question
      { currentQuestionIndex = 0;}
      
      // Get the string at that index in the questions array
      NSString *questions = [questions objectAtIndex:currentQuestionIndex];
      
      // Log the string to the console
      NSLog(@"displaying question: %0", question);
      
      //Displaying the string in the question field
      [questionField setText];
      //Clear the answer field
      [answerFIeld setText:@"???"];
    

    }

    }

  • (IBAction)showAnswer:(id)sender
    {
    // What is the answer to the current questions?
    NSString *answer = [answers objectAtIndex:currentQuestionIndex];
    //Display it in the answer field
    [answerField setText:answer];
    }

@end
[/code]

and the header file:

#import <UIKit/UIKit.h>

@interface QuizViewController : UIViewController
{
    int currentQuestionIndex;
    
    // The model objects
    NSMutableArray *questions;
    NSMutableArray *answers;
    
    // The view objects
    
    IBOutlet UILabel *questionField;
    IBOutlet UILabel *answerField;
}

- (IBAction)showQuestion:(id)sender;
- (IBAction)showAnswer:(id)sender;

@end