【问题标题】:ViewController's view not showing in NSBox with cocoa MacViewController 的视图未在 NSBox 中显示可可 Mac
【发布时间】:2012-03-22 14:04:45
【问题描述】:

我对 Mac 开发中的可可非常陌生。我目前正在努力让 viewController 的视图显示为 NSBox 的 contentView。相关代码如下所示:

// AccountsViewController.h. ManagingViewController is a custom subclass of NSViewController
// as of Cocoa Programming for Mac.
@interface AccountsViewController : ManagingViewController
{
    LoginViewController *loginViewController;
}

@property (strong) IBOutlet NSBox *box; 

// Implementation

@implementation AccountsViewController
@synthesize box;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Initialization code here.

        // Should display the view in the contentView(!?!)
        loginViewController = [[LoginViewController alloc]   initWithNibName:@"LoginViewController" bundle:nil];
        box.contentView = loginViewController.view;
    }

    return self;
}

目前,框的 contentView 中没有显示任何内容。我应该怎么做才能让 viewControllers 视图进入框中?

【问题讨论】:

    标签: macos cocoa nsbox


    【解决方案1】:

    问题在于 init 为时过早,无法添加/更改视图。在 AccountsViewController 上实现 awakeFromNib 方法并在那里设置内容视图。加载 nib 并且一切准备就绪后,将在您的类上调用 awakeFromNib。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多