search

Home  >  Q&A  >  body text

objective-c - cocoa-如何用ViewController加载一个custom view

我正在尝试着做一个状态栏应用。
AppDelegate中追踪鼠标动作。然后让nib对应的ViewController来调用加载view的函数。

//AppDelegate.h
@property myViewController *viewController;

//AppDelegate.m
@synthesize viewController;

- (IBAction)clickPreferences:(id)sender {
    [viewController showView:sender];
}

//myViewController.m
@property (strong) IBOutlet NSView *preferencesView;

-(void)showView:(id)sender{
        self.view = self.preferencesView; //here preferencesView is an IBOutlet property
    [self loadView];
}

错误信息:

-[myViewController loadView] loaded the "Preferences" nib but no view was set.

Preferences.xib中只有一个custom view。
我觉得应该不需要一个NSWindow。请问加载一个view需要哪些条件?如何调用?

高洛峰高洛峰2758 days ago487

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-02 09:23:44

    What the hell are you talking about? Is this really iOS?
    NSView is an object of Cocoa. How can it be iOS
    Is UIView good?

    reply
    0
  • Cancelreply