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)
私のプロジェクトがこのzipにある理由を誰かに教えてもらえますか
2 に答える
コードは明らかにこのScramblerModel
クラスを参照していScramblerModel.m
ますが、プロジェクトにファイルを含めていません。
したがって、まず、あなたの を見ると、次のように表示されますCompile Sources
。
モデルの追加で「+」ボタンをクリックしてください。も同様に使用するため、これScramblerPlayer
も同様に追加する必要があるため、これも追加しないと、別のリンカ エラーが発生します。
次に、使用するストーリーボードをアプリに伝えることを忘れないでください。
3 番目に、.h には、すべてのプロパティに対して定義されたインスタンス変数 (ivar) がありますIBOutlet
。これは問題です。これは、@synthesize
ステートメントが先頭のアンダースコアで ivars をインスタンス化しているためですが、.h (およびコード) は何にも接続されていない重複する ivars を参照しているためです。たとえば、プロパティremainingTime
があり、 ( ivar@synthesize remainingTime = _remainingTime
を作成している) があります。_remainingTime
したがって、明示的に宣言された ivarremainingTime
はプロパティに接続されていないremainingTime
ため、その ivar を使用しても、名前が似ているにもかかわらず、ユーザー インターフェイスは更新されません。
(a) プロパティに対して明示的に宣言された ivar を取り除く。(b) コードを変更して、プロパティ ( self.remainingTime
ivar など) を参照します_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
ただし、プロジェクトをコンパイルすると、多くのエラーが発生します。これは、コードが古い冗長な (そして名前が間違っている) ivar を誤って参照していたためです。したがって、たとえば、次のviewDidLoad
ような行がありました。
remainingTime.text = [NSString stringWithFormat:@"%i", gameModel.time];
playerScore.text = [NSString stringWithFormat:@"%i", gameModel.score];
それらは次のとおりです。
self.remainingTime.text = [NSString stringWithFormat:@"%i", gameModel.time];
self.playerScore.text = [NSString stringWithFormat:@"%i", gameModel.score];
誤った ivar を参照していたすべての場所で、この修正を繰り返すだけです。
それらをプロジェクトのビルド フェーズに追加するのを忘れると、「アーキテクチャ i386 の未定義のシンボル」というエラーが表示されます。したがって、実装ファイルを Compile Sources に追加し、Xib ファイルを Copy Bundle Resources に追加します。
Go to Scramblr Project -> Targets (Scrambl) -> Build Phases -> Complite Sources -> Add a ScramblerModel.m and ScramblerPlayer.m