Two issues in QuizViewController.m


#1

I am getting Method definition for ‘showAnswer.’ not found for the @implementation line and I am getting the error that I cannot assign ‘self’ outside of a methos in the init family for the self= [super… line. Any help would be greatly appreciated :slight_smile:

[code]#import “QuizViewController.h”

@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 make pointers to them
    questions = [[NSMutableArray alloc] init];
    answers = [[NSMutableArray alloc] init];

      //Questions and Answers for Arrays
      [questions addObject:@"What is Dylan's body made of?"];
      [answers addObject:@"Spaghetti"];
      
      [questions addObject:@"What is Hanna's middle name?"];
      [answers addObject:@"Kimbrough"];
      
      [questions addObject:@"Who is Hanna's oldest child?"];
      [answers addObject:@"Brown Bear"];
    

    }
    return self;
    }

  • (IBAction)showQuestion:(id)sender

{
//Step to the next question
currentQuestionIndex++;

//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 *question = [questions objectAtIndex:currentQuestionIndex];

//Log the string to the console
NSLog(@"displaying question: %@", question);

//Display the string in the question field
[questionField setText];

//Clear answer field
[answerField setText:@"???"];

}

  • (IBAction)ShowAnswer:(id)sender

{
//What is the answer to the current question?
NSString *answer = [answers objectAtIndex:currentQuestionIndex];

//Display it in the answer field
[answerField setText:answer];

}

@end
[/code]


#2

There is a spelling error (incorrect letter case) in the method name:

[quote]- (id)initwithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { ... }[/quote]
And in here:

[quote][code]

  • (IBAction)ShowAnswer:(id)sender
    {

    }
    [/code][/quote]
    You must type in exactly as shown in the book. Case does matter!

#3

Thank you so much! Embarrassed it was something as simple as case sensitivity.