Loading NSView subclass from a XIB

一世执手 提交于 2019-12-12 01:46:07

问题


I need to use a custom view into a NSMenuItem. I've created a new view XIB and customized the view in it. How can I load that view and set it in the NSMenuItem using the setView: method?

UPDATE: I've found a solution but now the menu item with the custom view doesn't highlight on mouse over. Ho can I solve this problem?


回答1:


I've created a NSViewController subclass and set it as the file's owner in the XIB. Then I've set the view outlet of the file's owner to the view in the XIB and finally when needed I've instantiated the view controller and set it's view as the NSMenuItem view with the following code:

CustomViewController *viewController = [[CustomViewController alloc] initWithNibName:@"NibName" bundle:nil];

NSMenuItem *menuItem = [[NSMenuItem alloc] init];
[menuItem setView:[viewController view]];


来源:https://stackoverflow.com/questions/3742720/loading-nsview-subclass-from-a-xib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!