本文介绍了iOS 新手.预期的表达错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..这似乎不寻常,因为该方法与我的 showAnswer 方法完全相同,所以我想我会在这里问.
It seems unusual as the method is the exact same as my showAnswer method, so I thought I'd ask here.
#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
推荐答案
在方法中
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
你之前缺少一个右括号
return self;
这篇关于iOS 新手.预期的表达错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论