无法将(NSApplication)的(View)出口连接到(NSView)

时间:2018-10-12 07:23:25

标签: objective-c xcode macos

我正在使用Xcode 10.0-macOS 10.14(Mojave)。我当时正在为我的学校项目开发一个应用,该应用以行的形式显示电影列表以及他们的海报和评分明星。每当我尝试启动我的应用程序时,都会出现错误:

  

[默认]无法加载Info.plist异常(eGPUOverrides)

但是,这似乎是系统的问题(正如我在Apple论坛上阅读的那样)...第二个错误:

  

无法将(视图)插座从(NSApplication)连接到(NSView):缺少设置器或实例变量

这些错误是否存在某种联系?我正在查看.xib文件,尝试将Main.storyboard设置为主界面,但是我的视图是空的...使用.xib文件,我什么都没有-应用程序启动,但是仅显示这两个错误。这是代码:

MasterViewController.m

#import "MasterViewController.h"
#import "NSObject+IntengineMovieData.h"
#import "NSObject+IntengineMovieDoc.h"

@interface MasterViewController ()

@end

@implementation MasterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do view setup here.
}

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];

    if([tableColumn.identifier isEqualToString:@"MoviesColumn"]) {
        IntengineMovieDoc *movieDoc = [self.movies objectAtIndex:row];
        cellView.imageView.image = movieDoc.thumbImage;
        cellView.textField.stringValue = movieDoc.data.title;
        return cellView;
    }
    return cellView;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
    return [self.movies count];
}

@end

AppDelegate.m

#import "AppDelegate.h"
#import "NSObject+IntengineMovieDoc.h"
#include "MasterViewController.h"

@interface AppDelegate ()
@property (nonatomic, strong) IBOutlet MasterViewController *masterViewController;
@property (assign) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.masterViewController = [[MasterViewController alloc]
                                 initWithNibName:@"MasterViewController" bundle:nil];

    IntengineMovieDoc *movie1 = [[IntengineMovieDoc alloc] initWithTitle:@"The Godfather" rating:5 thumbImage:[NSImage imageNamed:@"TheGodfatherThumb.jpg"] fullImage:[NSImage imageNamed:@"TheGodfather.jpg"]];

    IntengineMovieDoc *movie2 = [[IntengineMovieDoc alloc] initWithTitle:@"Tree of Life" rating:4 thumbImage:[NSImage imageNamed:@"TreeOfLifeThumb.jpg"] fullImage:[NSImage imageNamed:@"TreeOfLife.jpg"]];

    IntengineMovieDoc *movie3 = [[IntengineMovieDoc alloc] initWithTitle:@"Taxi Driver" rating:5 thumbImage:[NSImage imageNamed:@"TaxiDriverThumb.jpg"] fullImage:[NSImage imageNamed:@"TaxiDriver.jpg"]];

    NSMutableArray *movies = [NSMutableArray arrayWithObjects: movie1, movie2, movie3, nil];
    self.masterViewController.movies = movies;

    [self.window.contentView addSubview:self.masterViewController.view];
    self.masterViewController.view.frame = ((NSView*)self.window.contentView).bounds;
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}
@end

编辑1:好的,看来我在“查看面板”的Referencing Outlets中有一个额外的插座。我没有添加,但是删除此链接后,应用程序也不会显示。现在,它仅显示此错误:

  

[默认]无法加载Info.plist异常(eGPUOverrides)

1 个答案:

答案 0 :(得分:0)

由于您正在IBOutlet内实例化新实例,因此无需为视图控制器创建applicationDidFinishLaunching

此外,您应将masterViewController设置为窗口的rootViewController,如下所示:

self.window.rootViewController = self.masterViewController;
[self.window makeKeyAndVisible];

您可能必须先创建一个新窗口:

self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];