0

monomac で hello world アプリケーションをコンパイルしようとしています。XCode で .xib ファイルを変更しました。ラベルとボタン コントロールをフォームに追加しました。その後、次のコードを MainWindowController.h に追加しました。

@interface MainWindowController : NSWindowController {
    NSButton *_helloButton;
    NSTextField *_helloLabel;
}
@property (nonatomic, retain) IBOutlet NSButton *helloButton;
@property (nonatomic, retain) IBOutlet NSTextField *helloLabel;
- (IBAction)helloButtonClick:(id)sender;

そして、このコードは XCode、MainWindowController.m によって自動的に生成されました。

@synthesize helloButton = _helloButton;
@synthesize helloLabel = _helloLabel;
- (IBAction)helloButtonClick:(id)sender {
} 

Xamarin Studio に戻った後、次のコードを MainWindowController.cs に追加しました。

partial void helloButtonClick (NSObject sender) 
{
   helloLabel.StringValue = "Hello";
}

MainWindow.designer.cs では、次のコードが自動的に追加されました。

    [Outlet]
    MonoMac.AppKit.NSButton helloButton { get; set; }
    [Outlet]
    MonoMac.AppKit.NSTextField helloLabel { get; set; }
    [Action ("helloButtonClick:")]
    partial void helloButtonClick (MonoMac.Foundation.NSObject sender);

しかし、この方法でラベルにアクセスするには問題があります。helloButton をクリックすると、NullExeption が発生します。helloLabel が作成されていないようです。helloLabel は null です。しかし、helloButton は正常に機能しています。

また、AwakeFromNib() メソッドからラベルにアクセスしようとしました。結果は同じです。

誰かがそれをどのように行うべきかを明確に説明できますか? MacOSX 10.8、XamarinStudio 4.0.3、および XCode 4.6.1 を使用しています。ありがとうございました!

4

0 に答える 0