我在运行应用程序时得到"Apple Mach-O Linker Error"

Ale*_*man 1 xcode ios ios5

有人可以告诉我为什么我得到
Undefined symbols for architecture i386: "_OBJC_CLASS_$_ScramblerModel", referenced from: objc-class-ref in ViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 我的项目是在这个拉链

Rob*_*Rob 5

您的代码显然是引用此类ScramblerModel,但您尚未将该ScramblerModel.m文件包含在项目中.

所以,首先,如果你看一下Compile Sources,它会说:

没有包含模型

继续并在添加模型时单击"+"按钮.您可能也希望这样做ScramblerPlayer,因为您也使用该类,因此如果您不添加该类,则会出现另一个链接器错误.

现在添加了加扰器模型

其次,不要忘记告诉应用程序使用哪个故事板:

故事板

第三,您的.h具有为您的所有IBOutlet属性定义的实例变量(ivars).这是一个问题,因为你的@synthesize语句是使用前导下划线实例化ivars,但你的.h(和你的代码)指的是没有连接到任何东西的重复的ivars.例如,你有一个属性remainingTime,你有一个@synthesize remainingTime = _remainingTime(创建一个_remainingTimeivar).因此,您明确声明的ivar remainingTime未与您的remainingTime属性相关联,因此如果您使用该ivar,则不会产生用户界面更新,尽管名称相似.

您可以通过以下方法解决问题并简化代码:(a)清除属性的明确声明的ivars; (b)更改您的代码以引用该属性,例如self.remainingTimeivar _remainingTime.所以,你的.h被简化并变成:

//
//  ViewController.h
//  Scrambler
//
//  Created by Alex Grossman on 8/26/12.
//  Copyright (c) 2012 Alex Grossman. All rights reserved.
//

#import <UIKit/UIKit.h>

@class ScramblerModel;

@interface ViewController : UIViewController{
    ScramblerModel* gameModel;
    NSTimer* gameTimer;
}
@property (weak, nonatomic) IBOutlet UILabel *high;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *skipButton;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *restartButton;
@property (weak, nonatomic) IBOutlet UILabel *playerScore;
@property (weak, nonatomic) IBOutlet UILabel *remainingTime;
@property (weak, nonatomic) IBOutlet UILabel *scrambledWord;
@property (weak, nonatomic) IBOutlet UITextField *guessTxt;

-(IBAction)guessTap:(id)sender;
-(IBAction)restart:(id)sender;
-(IBAction)skip:(id)sender;
-(IBAction)category:(id)sender;
-(void) endGameWithMessage:(NSString*) message;

@end
Run Code Online (Sandbox Code Playgroud)

编译项目时,会遇到很多错误,因为您的代码错误地引用了那些旧的,冗余的(和错误名称的)ivars.因此,例如,在你的viewDidLoad行中你有这样的行:

remainingTime.text = [NSString stringWithFormat:@"%i", gameModel.time];
playerScore.text = [NSString stringWithFormat:@"%i", gameModel.score];
Run Code Online (Sandbox Code Playgroud)

那应该是:

self.remainingTime.text = [NSString stringWithFormat:@"%i", gameModel.time];
self.playerScore.text = [NSString stringWithFormat:@"%i", gameModel.score];
Run Code Online (Sandbox Code Playgroud)

只需对你指的是错误的伊娃所重复这一修正.