なぜメインファイルのヘッダーファイルの @properties を認識しないのでしょうか?

StackOverflow https://stackoverflow.com/questions/1116690

質問

UIView.h

#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
役に立ちましたか?

解決

ちょっとクレイジーになってる @synthesizeそうですか?ここでのあなたの主な問題は次のとおりだと思います @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

他のヒント

最初の問題は、UIKit にすでに存在するクラスに UIView という名前を付けていることです。見る @ウィリアムさん これを解決するためのアドバイス。

必要なのは 1 つだけです @synthesize プロパティごとに、プロパティ名がインスタンス変数名と一致する場合は、.m ファイルで次のようなことを行うだけで済みます。

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

また、入手時に問題が発生する可能性があります。 IBAction 動作する方法。ターゲットとアクションのリンケージにメソッドを使用するには、戻り値の型が次のとおりである必要があります。 IBAction (あなたは正しいです)そして、 id 送信者を表すパラメータ。正規のメソッド シグネチャは次のようになります。

- (IBAction) goButtonClicked:(id)sender;

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top