【发布时间】:2014-10-15 16:33:04
【问题描述】:
我是一名 iOS 开发人员,我想创建一个简单的桌面应用程序。我以为切换会很完美,但事实并非如此。
我创建了一个可可应用程序(来自 xCode 模板)。现在我不想使用用户界面构建器和其他东西,所以我这样写了我的第一个控制器:
@interface MainViewController ()
@property (nonatomic, strong) NSTextView *test;
@end
@implementation MainViewController
-(instancetype) init
{
self = [super init];
if(self)
{
NSLog(@"%s", __PRETTY_FUNCTION__);
_test = [[NSTextView alloc] init];
[_test setString:@"DKDDK"];
[self.view addSubview:_test];
[_test mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
}
return self;
}
@interface MainViewController : NSViewController
@end
我只使用模板创建的 NSWindow:
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
MainViewController * mainView = [[MainViewController alloc] init];
[self.window.contentView addSubview:mainView.view];
mainView.view.frame = ((NSView*)self.window.contentView).bounds;
}
当我运行它给我的应用程序时:
[NSViewController loadView] 加载了“(null)” nib 但没有设置视图。
我不知道如何解决这个问题。如何像在 iOS 上一样创建没有 nib 的应用?
【问题讨论】:
标签: objective-c cocoa