objective-c - iOS 新手。预期的表达错误?

标签 objective-c ios xcode

这似乎很不寻常,因为该方法与我的 showAnswer 方法完全相同,所以我想我应该在这里问一下。

#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;

关于objective-c - iOS 新手。预期的表达错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168253/

相关文章:

objective-c - 如何将 UIButtons 旋转 90 度,而不会出现自动布局错误?

iphone - 主线程在SCNetworkReachabilityGetFlags上被阻止

android - Android 上的离线 Web 应用程序 HTML5

ios - 带 SwiftUI 的播放/停止按钮

ios - iAd 横幅在 segue 上变白

iphone - iOS中的AES算法实现

iphone - 获取 UIWebView URL 的查询

iphone - "Reachability.h"“Reachability.m 在添加它们时给出 Apple mach-o 链接器错误

ios - Xcode UI 测试、开发语言、后备翻译和 CI 服务器

xcode - UICollectionView 滚动到索引处的项目