简体   繁体   English

解雇nspopover不起作用

[英]dismiss nspopover doesn't work

i have a big problem, which i can't solve since a week. 我有一个大问题,一个星期以来我无法解决。 My Situation: 我的情况:

I have an ViewController with a NSTableview and custom cells. 我有一个带有NSTableview和自定义单元格的ViewController。 in each sell is a nsbutton. 在每个销售中都有一个nsbutton。 if you pressed a button, a nspopover will appear. 如果按下按钮,将显示nspopover。 but you can close it with the "close"-button, which is assigned to the dismiss-function. 但是您可以使用分配给解除功能的“关闭”按钮将其关闭。 i you pressed the plus button (out of the tableview) the same popover will appear and can close with the "close"-button without problems. 如果您按下加号按钮(在表格视图之外),将出现相同的弹出窗口,并且可以使用“关闭”按钮关闭它而不会出现问题。

what do i wrong? 我怎么了 i attached the example project via google drive. 我通过谷歌驱动器附加了示例项目。 thanks for your help: 谢谢你的帮助:

Download: https://drive.google.com/open?id=0B8PBtMQt9GdORUxQRXRISWR5dWs 下载: https : //drive.google.com/open?id=0B8PBtMQt9GdORUxQRXRISWR5dWs

dismissViewController doesn't work if the view controller doesn't have a presenting view controller (I don't know why). 如果视图控制器没有显示的视图控制器(我不知道为什么), dismissViewController不起作用。 Starting from the downloaded project, make the following changes: 从下载的项目开始,进行以下更改:

  1. Move the showPopover action from CustomCell to TableViewController . showPopover操作从CustomCell移到TableViewController Change the type of sender to NSButton . sender的类型更改为NSButton

  2. Present the view controller instead of showing the popover. 呈现视图控制器,而不是显示弹出窗口。

     @IBAction func showPopover(_ sender: NSButton) { let vcPopover = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "vcPopover") as! NSViewController self.presentViewController(vcPopover, asPopoverRelativeTo : sender.bounds, of : sender, preferredEdge: .maxX, behavior: .transient) } 
  3. Connect the action of the button in the table view to the Table View Controller and action showPopover . 将表视图中按钮的操作连接到“表视图控制器”和操作showPopover

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM