Swift - warning when choosing files (Cocoa)

南笙酒味 提交于 2019-12-13 03:35:31

问题


I want to make a button in my app to select files with Finder using Swift.

@IBAction func selectFiles(sender : NSButton) {
    let openDlg = NSOpenPanel()
    openDlg.allowsMultipleSelection = true
    openDlg.canChooseFiles = true
    openDlg.canChooseDirectories = true
    if openDlg.runModal() == NSOKButton{
        files = openDlg.URLs
    }
}

When I run this code, the following warning occurs.

Unable to simultaneously satisfy constraints:
(
    "<NSAutoresizingMaskLayoutConstraint:0x608000095450 h=-&- v=-&- H:|-(0)-[NSView:0x608000125b40]   (Names: '|':FIFinderView:0x600000143de0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x6080000954a0 h=-&- v=-&- H:[NSView:0x608000125b40]-(0)-|   (Names: '|':FIFinderView:0x600000143de0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000095680 h=--& v=--& H:[FIFinderView:0x600000143de0(712)]>",
    "<NSLayoutConstraint:0x60800008cbc0 H:[NSView:0x608000125a00]-(0)-|   (Names: '|':NSView:0x608000125b40 )>",
    "<NSLayoutConstraint:0x60800008cc10 H:|-(0)-[NSView:0x608000125a00]   (Names: '|':NSView:0x608000125b40 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000092ed0 h=-&- v=-&- H:|-(0)-[NSClipView:0x100541110]   (Names: '|':FI_TSidebarScrollView:0x6000001c1b30 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000092f20 h=-&- v=-&- H:[NSClipView:0x100541110]-(15)-|   (Names: '|':FI_TSidebarScrollView:0x6000001c1b30 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x6080000935b0 h=-&- v=-&- H:|-(0)-[FI_TSidebarScrollView:0x6000001c1b30]   (Names: '|':NSView:0x600000123660 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000093600 h=-&- v=-&- H:[FI_TSidebarScrollView:0x6000001c1b30]-(0)-|   (Names: '|':NSView:0x600000123660 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000093790 h=-&- v=-&- H:|-(0)-[NSView:0x600000123660]   (Names: '|':FI_TSidebarSplitView:0x600000143f40 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x6080000937e0 h=-&- v=-&- H:[NSView:0x600000123660]-(709)-|   (Names: '|':FI_TSidebarSplitView:0x600000143f40 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000095270 h=-&- v=-&- H:|-(0)-[FI_TSidebarSplitView:0x600000143f40]   (Names: '|':NSView:0x608000125a00 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x6080000952c0 h=-&- v=-&- H:[FI_TSidebarSplitView:0x600000143f40]-(0)-|   (Names: '|':NSView:0x608000125a00 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60800008cbc0 H:[NSView:0x608000125a00]-(0)-|   (Names: '|':NSView:0x608000125b40 )>

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.  And/or, break on objc_exception_throw to catch this in the debugger.

Even if I don't get rid of this warning, my app runs well, but I want to know how to remove it.


回答1:


This is a problem with NSOpenPanel. A bug report on this has already been filed with Apple, but before they fix it I'm afraid there's not much you can do. Good thing your code runs well :)




回答2:


Go to your storyboard. On the left panel where the scenes are listed, you should be able to see a yellow dot. Click that to either adjust your views or your contraints



来源:https://stackoverflow.com/questions/25462675/swift-warning-when-choosing-files-cocoa

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