1

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
4

2 に答える 2

4

sに少し夢中になる@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
于 2009-07-12T19:57:15.693 に答える
0

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

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

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

また、メソッドを機能させる際に問題が発生する可能性がありますIBAction。ターゲットとアクションのリンクにメソッドを使用するには、IBAction(正しい) の戻り値の型を持ちid、送信者を表すパラメーターを受け入れる必要があります。正規のメソッド シグネチャは次のようになります。

- (IBAction) goButtonClicked:(id)sender;

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

于 2009-07-15T03:45:40.503 に答える