objective-c - 如何修复 : Incomplete Implementation

标签 objective-c ios xcode implementation

如何解决未完成实现的问题?

Controller.m View :

    #import "Quiz_GameViewController.h"

@implementation Quiz_GameViewController

@synthesize theQuestion, timer, theScore, theLives, answerOne, answerTwo, answerThree, answerFour, theQuiz
    ;



-(void)askQuestion
{
    // Unhide all the answer buttons.
    [answerOne setHidden:NO];
    [answerTwo setHidden:NO];
    [answerThree setHidden:NO];
    [answerFour setHidden:NO];

    // Set the game to a "live" question (for timer purposes)
    questionLive = YES;

    // Set the time for the timer
    time = 8.0;

    // Go to the next question
    questionNumber = questionNumber + 1;

    // We get the question from the questionNumber * the row that we look up in the array.

    NSInteger row = 0;
    if(questionNumber == 1)
    {
        row = questionNumber - 1;
    }
    else
    {
        row = ((questionNumber - 1) * 6);
    }

    // Set the question string, and set the buttons the the answers
    NSString *selected = [theQuiz objectAtIndex:row];
    NSString *activeQuestion = [[NSString alloc] initWithFormat:@"Question: %@", selected];
    [answerOne setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
    [answerTwo setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
    [answerThree setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
    [answerFour setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
    rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];

    // Set theQuestion label to the active question
    theQuestion.text = activeQuestion;

    // Start the timer for the countdown
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];

    [selected release];
    [activeQuestion release];
}

-(void)updateScore
{
    // If the score is being updated, the question is not live
    questionLive = NO;

    [timer invalidate];

    // Hide the answers from the previous question
    [answerOne setHidden:YES];
    [answerTwo setHidden:YES];
    [answerThree setHidden:YES];
    [answerFour setHidden:YES];
    NSString *scoreUpdate = [[NSString alloc] initWithFormat:@"Score: %d", myScore];
    theScore.text = scoreUpdate;
    [scoreUpdate release];

    // END THE GAME.
    NSInteger endOfQuiz = [theQuiz count];
    if((((questionNumber - 1) * 6) + 6) == endOfQuiz)
    {
        // Game is over.
        if(myScore > 0)
        {
            NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Game Over!\nNice Game \nYou scored %i!", myScore];
            theQuestion.text = finishingStatement;
            [finishingStatement release];
        }
        else
        {
            NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Game Over!\n You're terrible! \nYou scored %i.", myScore];
            theQuestion.text = finishingStatement;
            [finishingStatement release];
        }
        theLives.text = @"";

        // Make button 1 appear as a reset game button
        restartGame = YES;
        [answerOne setHidden:NO];
        [answerOne setTitle:@"Restart game!" forState:UIControlStateNormal];

    }
    else
    {
    // Give a short rest between questions
    time = 3.0;

    // Initialize the timer
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
    }
}

-(void)countDown
{
    // Question live counter
    if(questionLive==YES)
    {
        time = time - 1;
        theLives.text = [NSString stringWithFormat:@"Time remaining: %i!", time];

        if(time == 0)
        {
            // Loser!
            questionLive = NO;
            theQuestion.text = @"HAHA now you lost alot of points!";
            myScore = myScore - 1000;
            [timer invalidate];
            [self updateScore];
        }
    }
    // In-between Question counter
    else
    {
        time = time - 1;
        theLives.text = [NSString stringWithFormat:@"Next question coming in...%i!", time];

        if(time == 0)
        {
            [timer invalidate];
            theLives.text = @"";
            [self askQuestion];
        }
    }
    if(time < 0)
    {
        [timer invalidate];
    }
}


- (IBAction)buttonOne
{
    if(questionNumber == 0){
        // This means that we are at the startup-state
        // We need to make the other buttons visible, and start the game.
        [answerTwo setHidden:NO];
        [answerThree setHidden:NO];
        [answerFour setHidden:NO];
        [self askQuestion];
    }
    else
    {
        NSInteger theAnswerValue = 1;
        [self checkAnswer:(int)theAnswerValue];
        if(restartGame==YES)
        {
            // Create a restart game function.
        }
    }
}

- (IBAction)buttonTwo
{
    NSInteger theAnswerValue = 2;
    [self checkAnswer:(int)theAnswerValue];
}

- (IBAction)buttonThree
{
    NSInteger theAnswerValue = 3;
    [self checkAnswer:(int)theAnswerValue];
}

- (IBAction)buttonFour
{
    NSInteger theAnswerValue = 4;
    [self checkAnswer:(int)theAnswerValue];
}

// Check for the answer (this is not written right, but it runs)
-(void)checkAnswer:(int)theAnswerValue
{
    if(rightAnswer == theAnswerValue)
    {
        theQuestion.text = @"Daaamn";
        myScore = myScore + 50;
    }
    else
    {
        theQuestion.text = @"hahaha!";
        myScore = myScore - 50;
    }
    [self updateScore];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    questionLive = NO;
    restartGame = NO;
    theQuestion.text = @"Think you can do it?";
    theScore.text = @"Score:0";
    theLives.text = @"";
    questionNumber = 0;
    myScore = 0;
    myLives = 0;
    [answerOne setTitle:@"I think i can!" forState:UIControlStateNormal];
    [answerTwo setHidden:YES];
    [answerThree setHidden:YES];
    [answerFour setHidden:YES];
    [self loadQuiz];
}

-(void)loadQuiz
{
    // This is our forced-loaded array of quiz questions.
    // FORMAT IS IMPORTANT!!!!
    // 1: Question, 2 3 4 5: Answers 1-4 respectively, 6: The right answer
    // THIS IS A TERRIBLE WAY TO DO THIS. I will figure out how to do nested arrays to make this better.
    NSArray *quizArray = [[NSArray alloc] initWithObjects:@"Who is the president in USA?",@"Me",@"Obama",@"George Bush",@"Justin Bieber",@"2",
                          @"Capital in Norway?", @"Bergen", @"Trondheim", @"Oslo", @"Bærum", @"3",
                          @"The right answer is 3!", @"41", @"24", @"3", @"9", @"1",
                          @"Do I have a cat?", @"Yes", @"No", @"No, you have a dog", @"No, you have a flying hamster", @"4",
                          @"Baba", @"Daba jaba?", @"Laba daba haba?", @"Saba daba gaba?", @"Haba haba?", @"4",
                          nil];
    self.theQuiz = quizArray;
    [quizArray release];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [theQuestion release];
    [theScore release];
    [theLives release];
    [answerOne release];
    [answerTwo release];
    [answerThree release];
    [answerFour release];
    [theQuiz release];
    [timer release];
    [super dealloc];
}

@end

我是新来的,这是来自互联网的示例脚本...我用它来学习 Objective-C 和 Cocoa 语言...ViewController.h :

#import <UIKit/UIKit.h>

@interface Quiz_GameViewController : UIViewController {
    IBOutlet    UILabel     *theQuestion;
    IBOutlet    UILabel     *theScore;
    IBOutlet    UILabel     *theLives;
    IBOutlet    UIButton    *answerOne;
    IBOutlet    UIButton    *answerTwo;
    IBOutlet    UIButton    *answerThree;
    IBOutlet    UIButton    *answerFour;
    NSInteger myScore;
    NSInteger myLives;
    NSInteger questionNumber;
    NSInteger rightAnswer;
    NSInteger time;
    NSArray *theQuiz;
    NSTimer *timer;
    BOOL questionLive;
    BOOL restartGame;
}

@property (retain, nonatomic) UILabel   *theQuestion;
@property (retain, nonatomic) UILabel   *theScore;
@property (retain, nonatomic) UILabel   *theLives;
@property (retain, nonatomic) UIButton  *answerOne;
@property (retain, nonatomic) UIButton  *answerTwo;
@property (retain, nonatomic) UIButton  *answerThree;
@property (retain, nonatomic) UIButton  *answerFour;
@property (retain, nonatomic) NSArray *theQuiz;
@property (retain, nonatomic) NSTimer *timer;

-(IBAction)buttonOne;
-(IBAction)buttonTwo;
-(IBAction)buttonThree;
-(IBAction)buttonFour;

-(void)checkAnswer;

-(void)askQuestion;

-(void)updateScore;

-(void)loadQuiz;

-(void)countDown;

@end

最佳答案

在您的头文件中,您声明了方法 -(void)checkAnswer,而在 .m 文件中您声明了它 -(void)checkAnswer:(int)theAnswerValue.

这意味着您的 .m 文件正在寻找一个方法 -(void)checkAnswer,它不存在,它会产生一个 Incomplete implementation 警告。只需将 .h 文件中的声明更改为 - (void)checkAnswer:(int)theAnswerValue,就可以了。

关于objective-c - 如何修复 : Incomplete Implementation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13221253/

相关文章:

ios - 找不到 Objective-C 桥接头部分

ios - 如何获取 AppIcon 的 UIImage?

ios - 使用可编码的对象

ios - 自动布局 - 根据屏幕尺寸动态更改 subview 尺寸

ios - 无法将应用程序上传到 iTunes Connect

ios - Storyboard需要更多时间来加载

objective-c - 无法找出 "Unrecognized selector sent to instance"来源

objective-c - XCode - 查找错误

ios - 在 Xcode 中设置分组单元格的宽度

xcode - 如何为此项目结构配置 cocoapod podspec 和 podfile?