2009-07-12 6 views
1

UIView.hメインファイルからヘッダーファイルの@propertiesを認識できないのはなぜですか?

#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 

@interface UIView : UIResponder { 
    IBOutlet UILabel *endLabel; 
    IBOutlet UIButton *goButton; 
    IBOutlet UITextField *textBox1; 
    IBOutlet UITextField *textBox2; 

    @property(nonatomic, retain) UILabel *endLabel; 
    @property(nonatomic, retain) UIButton *goButton; 
    @property(nonatomic, retain) UITextField *textBox1; 
    @property(nonatomic, retain) UITextField *textBox2; 
} 
- (IBAction)goButtonClicked; 
@end 

UIView.m

#import "UIView.h" 

@implementation UIView 

@synthesize textBox1, goButton; 
@synthesize textBox2, goButton; 
@synthesize textBox1, endLabel; 
@synthesize textBox2, endLabel; 
@synthesize goButton, endLabel; 

- (IBAction)goButtonClicked { 

} 

@end 
+0

あなたはUIViewを再実装しようとしています。このクラスは既に存在しており、確かに存在しているので、これは明らかに良いことではありません。あなたのクラスの名前を変更し、UIViewのサブクラスとして実装する必要があります(MyViewなど)。 –

答えて

4

@synthesize sのクレイジーなビットを行く、我々は何ですか?私はあなたの主な問題は、@propertyの宣言がの後にの後になる必要があるということです。@interfaceです。

コンパイラがグリーンランドのサイズの赤い旗を投げなかったことに驚きました。

さらに、カスタムサブクラスをUIViewにすることを意味します。 MyViewを使用します。

//MyView.m -- correct synthesize declaration 
@synthesize textBox1, goButton, textBox2, endLabel; 

//MyView.h -- correct interface declaration 
#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 

@interface MyView : UIView { 
    IBOutlet UILabel *endLabel; 
    IBOutlet UITextField *textBox1; 
    IBOutlet UITextField *textBox2; 
    IBOutlet UIButton *goButton; 
} 

@property(nonatomic, retain) UIButton *goButton; 
@property(nonatomic, retain) UILabel *endLabel; 
@property(nonatomic, retain) UITextField *textBox1; 
@property(nonatomic, retain) UITextField *textBox2; 

@end 
+0

実際に私はそれらを使い果たしましたが、それでも動作しません!私はただそこに置いて、何が起こるか見てみましょう... –

0

最初の問題は、既にUIKitに存在するクラスUIViewの名前を付けていることです。これを解決するには、@ Willihamののアドバイスを参照してください。

あなたが唯一のプロパティごとに1 @synthesizeを必要とする、とプロパティ名は、インスタンス変数名と一致した場合、あなただけの.mファイルにこのような何かをする必要がある必要があります。また

@synthesize endLabel; 
@synthesize goButton; 
@synthesize textBox1; 
@synthesize textBox2; 

、あなたがしていますIBActionメソッドを動作させるのに問題が発生する可能性があります。ターゲットアクションリンケージにメソッドを使用するには、返されるタイプがIBAction(正しいもの)で、送信者を表すidパラメーターを受け入れる必要があります。標準的なメソッドのシグネチャは次のようになります。

- (IBAction) goButtonClicked:(id)sender; 

私は実際には同じアクションを呼び出すために他の方法があるかもしれません、特に以来、それを明示的に呼び出すボタンに関連付けられていないメソッド名をお勧めします。 (たとえば、デスクトップアプリケーションを作成している場合は、同等のキーコマンドまたはメニューコマンドを使用しても同じことができます)。

関連する問題