2013-01-05 80 views
2

由於該方法與我的showAnswer方法完全相同,所以我認爲我會在這裏問。iOS新手。預期的表達錯誤?

#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 make 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 Vermond?"]; 
    [answers addObject:@"Montpelier"]; 

    [questions addObject:@"From what is cognac made?"]; 
    [answers addObject:@"Grapes"]; 

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

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

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

    // Clear the 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 
+4

纔可以寫出你從控制檯收到錯誤消息? – wigging

+3

錯誤是什麼? –

+0

@CarlNorum它在 - (IBAction)... – STANGMMX

回答

8

在該方法中

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 

你缺少一個右括號

return self; 
+0

實際上,在'return self;'之前的'}'聲音。 –

+0

+1這個括號最終在'@ end'的正上方:) – dasblinkenlight

+2

OP的注意事項:Xcode的** Re-Indent **命令(編輯器→結構→重新縮進)在這種情況下非常有用。事實上,它非常有用,你應該將它綁定到一個容易觸及的鍵。 –