Two issues in QuizViewController.m


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

//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];




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

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


  • (IBAction)ShowAnswer:(id)sender

    You must type in exactly as shown in the book. Case does matter!


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