Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 从菜单项调用popover崩溃_Cocoa_Swift_Popover - Fatal编程技术网

Cocoa 从菜单项调用popover崩溃

Cocoa 从菜单项调用popover崩溃,cocoa,swift,popover,Cocoa,Swift,Popover,我有一个工具栏按钮 @IBOutlet weak var testButton: NSToolbarItem! 这个按钮叫popover,效果很好 但是如果我试着从最上面的菜单项调用popover,我会崩溃。 我已经修改了popover的位置,使其显示在testButton的下方,与正常情况一样。评论如下 @IBAction func menuPreviewAndTestAction(sender: AnyObject) { var returnedHtmlString = check

我有一个工具栏按钮

@IBOutlet weak var testButton: NSToolbarItem!
这个按钮叫popover,效果很好

但是如果我试着从最上面的菜单项调用popover,我会崩溃。 我已经修改了popover的位置,使其显示在testButton的下方,与正常情况一样。评论如下

@IBAction func menuPreviewAndTestAction(sender: AnyObject) {
    var returnedHtmlString = checkEverythingAndCreateTheEncodedHtml(testButton)
    setEncodedHtmlToPreview(returnedHtmlString)
    var thebounds = self.testButton.view?.bounds // so i am givving bounds of button that narmally calls poover
    testingPopover.showRelativeToRect(thebounds!, ofView: sender as NSView, preferredEdge: NSMaxYEdge) // crashes
}

哦,天哪。。。我错过了更改ofView的机会,所有这些都与以下内容排序:

var thebounds = self.testButton.view?.bounds
        var theview = self.testButton.view
        testingPopover.showRelativeToRect(thebounds!, ofView: theview! as NSView,      preferredEdge: NSMaxYEdge)