How can I pin an NSPopover to a selected NSTableCellView in swift5
From the documentation of NSTableView.doubleAction
:
The clickedRow and clickedColumn properties allow you to determine which row and column the double-click occurred in or if, rather than in a row, the double-click occurred in a column heading.
@objc func tableViewDoubleAction(sender: NSTableView) {
let row = sender.clickedRow
From the documentation of clickedRow
:
The index of the row the user clicked to trigger an action message. Returns –1 if the user clicked in an area of the table view not occupied by table rows.
if row >= 0 {
NSTableView
has a method rect(ofRow:)
:
Returns the rectangle containing the row at the specified index.
let rowRect = sender.rect(ofRow: row)
Use this rect to position the popover
popover.show(relativeTo: rowRect, of: sender, preferredEdge: NSRectEdge.maxY)
Put it all together:
@objc func tableViewDoubleAction(sender: NSTableView) {
let row = sender.clickedRow
if row >= 0 {
// create the popover
let rowRect = sender.rect(ofRow: row)
popover.show(relativeTo: rowRect, of: sender, preferredEdge: NSRectEdge.maxY)
}
}
NSPopover padding content on one side
Proplem solved, but I still don't exactly know why it required solving. The NSPopovers content view (or at least mine) requires an origin point of X: 13, Y: 13. For some reason, only one of my views was getting this value.
To solve this, I subclassed NSView and overrode the setFrame method forcing its x and y to always be 13, 13
-(void)setFrame:(NSRect)frameRect {
[super setFrame:NSMakeRect(13, 13, frameRect.size.width, frameRect.size.height)];
}
NSScrollView/NSCollectionView on NSVisualEffectView cause flickering
Ok, seems disabling the "Autoresize Subviews" on the problematic view will do the trick.
Load WebView URL inside Notification Bar NSPopover
You have created the Outlet in IB for the UIWebView in your Custom View ? and strung it together?
Related Topics
How to Test an Optionset with a Switch Statement
Are Static Classes Supported by Swift
Context Menu Not Updating in Swiftui
Testing Protocol Conformance with Associated Types
Add Uiimage as Texture to a Plane in Realitykit
How to Save Value in Nsset Core Data (Swift)
Swiftui: Two-Finger Swipe ( Scroll ) Gesture
Building an Nsoutline View with Check Marks
How to Add an Admob Gadbannerview to Every View
Swift Client and Root Ssl Certificate Authentication
Bit Field Larger Than 64 Shifts in Swift
Enabling Gestures in Realitykit
Assemble a List of Users with Geofire/Firebase
Compiler Cannot Infer Return Type
Cant Change Navigation Bar Height iOS 11
How to Rotate an Arkit 4X4 Matrix Around Y Using Apple's Simd Library