2012-09-02 36 views
1

有人能告訴我爲什麼我收到越來越「蘋果Mach-O的連接錯誤」
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) 我的項目是在This zip進出口運行的應用程序

回答

5

您的代碼顯然是引用此ScramblerModel類,但你的避風港」 t將ScramblerModel.m文件包含在您的項目中。

因此,首先,如果你看看你Compile Sources,它說:

no model included

來吧,然後點擊添加在模型中的「+」按鈕。你也可能想爲ScramblerPlayer這麼做,因爲你也使用了這個類,所以如果你不這樣做,你會得到另一個鏈接器錯誤。

now added scrambler model

其次,不要忘記告訴應用使用什麼故事板:

storyboard

三,你的.h對所有IBOutlet的定義實例變量(高德)屬性。這是一個問題,因爲你的@synthesize語句是用一個前導下劃線實例化ivars,但是你的.h(和你的代碼)指的是沒有連接任何東西的重複ivars。例如,你有一個財產remainingTime,你有一個@synthesize remainingTime = _remainingTime(這是創建一個_remainingTime伊娃)。因此,您明確聲明的ivar remainingTime未連接到您的remainingTime屬性,因此如果使用該ivar,則不會出現用戶界面更新,儘管名稱相似。

您可以通過以下方法解決問題並簡化代碼:(a)爲您的屬性刪除顯式聲明的ivars;和(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 

當你編譯你的項目,你會得到很多的錯誤,但是,因爲你的代碼錯誤地引用那些老的,冗餘(和名不副實),高德。因此,例如,在你的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]; 

只是重複這種修正到處你指的錯誤的ivars。

+0

是啊,但現在模擬器不會加載 –

+0

應用和只是停留黑 –

+0

我只是做了,但現在我的標籤慣於更新到什麼有被告知在ViewController.m做,你知道這是爲什麼? –

0

如果您忘記將它們添加到您的項目構建階段中,您將收到錯誤「Undefined symbols for architecture i386」。因此,將您的實現文件添加到編譯源文件中,並將Xib文件添加到複製軟件包資源中。

Go to Scramblr Project -> Targets (Scrambl) -> Build Phases -> Complite Sources -> Add a ScramblerModel.m and ScramblerPlayer.m 
+0

非常感謝您 –

+0

爲什麼現在不用模擬器加載項目? –

相關問題