-2

OSX 10.7.5 - XCode 4.6.1 - iOS ではなくアプリケーション OSX。コードは非常に単純です。
A. Window > contentWiew > subView with ViewController > Button_ ボタンは を使用して作成されますViewController.xib

すべてが期待どおりに表示されますが、ボタンをクリックするとすべて失敗します。すべてのオブジェクトは ではありませんnil

ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
NSView *aView = [NSView new];
aView = [viewController view];
[[_window contentView] addSubview:aView];

コンソールで:

[NSContentSizeLayoutConstraint buttonAct:]: unrecognized selector sent to instance 0x1061178a0
4

1 に答える 1

0

You create a view controller which has a view associated with it. You create a new NSView. You overwrite your newly created NSView with the view controller's view. Finally, you add a reference to the view controller's view to the window's content view.

//this does the same as your above code
ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
//in ios, you typically don't add things straight to the window
[[_window contentView] addSubview:viewController.view];

This is saything that buttonAct: isn't class method for NSContentSizeLayoutConstraint.

[NSContentSizeLayoutConstraint buttonAct:]: unrecognized selector sent to instance 0x1061178a0
于 2013-07-30T16:55:03.423 に答える