NSTableView overlay - cocoa

Id like to add an overlay to an NSTableView when it is loading some data. I found this post which mentions using CALayer with a CIGaussianBlur but I cannot get anything to work. Does anyone know of any good tutorials for displaying an overlay on an NSTableView? (Or even just an NSView).

I've always found it easiest to do this by not futzing with the table view at all. Embed the table as a subview of another view (a container view, if you will). Add another subview to the container view that will be your overlay, just make sure it's in front of your table. Then you hide the overlay view when you don't need it, show it when you do.

Related

Cocoa: How to properly hide other views below NSImageView?

I have a view with several subviews (NSButton, NSTextField, NSPopUpButton) and a NSImageView with a spinner icon which should be displayed on top of the other views while data is retrieved from the web.
To display the NSImageView on top I have set
imageViewSpinner.wantsLayer = true
imageViewSpinner.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
The problem is, that the focus borders and PopUpButtons are still accessible/shining through the NSImageView (see attached video).
To solve this, I could iterate over all the other subviews and set them to "isHidden" or "disabled" but I wonder, if there is a cleaner solution to this problem, for example defining the NSImageView as topmost layer without things getting through?
You could put all of the other views inside of one container view and hide that.
You can also use a tab-less tab view to programmatically switch between view sub-hierarchies. (That basically achieves the same thing. It's better when there are more than 2 views to manage.)

Why do I need wantsLayer for Check Boxes in a Table View in macos

I have a simple cocoa app for macos, the whole UI is created programmatically i.e. I'm not using the interface builder (no xib-s, no storyboards).
I'm creating a scroll view, adding a table view with a single column and feeding it with cell views containing check boxes.
So the view structure looks like this:
window
root content view
scroll view
clip view (created automatically by the scroll view)
table view
cell view
check box
The problem is that the check box is behaving weirdly in this structure - it doesn't repaint itself when clicked. BUT - if you click it and then resize the window (I have auto-layout constraints there, too), then the table view is redrawn and the check box is redrawn too and thus updated.
I've been trying various things to localize the problem (I'm new to macos, therefore I tried pretty much everything) and found out that if I turn the wantsLayer on for the cell view or the check box itself, then check boxes start working properly.
If I don't wrap the table view into the scroll view, then everything works without wantsLayer, too. When I create check boxes out of the table view - just put them on the root view itself, they also work properly.
Please explain me why do I need the wantsLayer. Or maybe I need something else in reality and wantsLayer works just by accident?

Prototype Cells in UITableView not on top

It's really strange. The Prototype-Cell in my second UITableView isn't on top as it should be:
If I start moving it, than it's on top again, but after i drop it on my View, it is still in this strange way.
How can I change that?
As you see, the first Cell is okay, but the second isn't.
Well, it's difficult to understand using only an image, but I will give you some possible causes for that:
Have you applied a table header view by accident in the second table view? If you did, removing it will be the solution
Have you applied the proper view constraints in the table view and its cells?
If I were you, I would not try to embed two UITableViews in the same view controller this way, especially since you use storyboards with iOS 7. What I would do is to use embed segues. Just drag a container view for each of your view table views, and connect their embed segues to their appropriate table view controllers ( you need to create in the storyboard those, two). That way, you can set the constraints much easier, separate the logic between the two and have a cleaner interface. You can do that and see if that helps.

How can my code get notified when the user pastes or drags an image into NSImageView?

I have an instance of NSImageView. I have told InterfaceBuilder to allow the user to paste or drag an image into this view. This works. However, I don't see a way in the NSImageView or related documentation to get notified when this actually happens. I was expecting a delegate or some such, but I have been unable to find it. Any ideas?
This is what Cocoa Bindings does best.
Instead of talking to the view, simply have a property whose value is an image, and bind the image view's image binding to it; then, when you want to change the image in the image view yourself, all you have to do is set the value of the property, and the image view will notice the change.
The user pasting or dragging into the image view is essentially the same thing, partly in reverse: The paste or drop will change the value of the image view, which will then set the value of your property, which will cause anything else bound to it to notice the change and pick up the new value as before.
Aside from ripping out your existing send-explicit-messages-to-views code, this will require almost no code work: The only code you need is for your property. You'll hook up the Binding in IB.
See the Key-Value Coding Programming Guide and the Cocoa Bindings Programming Topics.
As for me the better way to override function
-(void)paste:(id)sender
But only if you have it in NSView based class which has NSResponder as parent

Cocoa: How to make table view draw custom views in each cell

I am learning Cocoa and trying to create an application for Mac that displays a simple book list. Each book is an NSView with its cover image, title and author. I want to present this list as a NSTableView with a single column and a book view in each cell. However i can't yet figure out how to display a custom view inside a table cell in interface builder or programmatically. Any tips would be very appreciated :)
Inso.
If all of your "book views" are the same size, why not use NSCollectionView / NSCollectionViewItem? It's a much cleaner solution (provided they're all sized the same).
Assuming a collection view wouldn't be a better solution, what you need to do is to write a custom cell. The column owns exactly one such cell, which the table view will use to draw the column's value for each row.
(If you came from the iPhone, yes, this is completely different from UITableView. Each NSTableColumn has exactly one cell, which it uses for every row.)
If you're using your NSView class somewhere else, then you could make it into a subclass of NSControl and have it use another instance of the same cell class. Like most controls, all the real work would be done by the cell, which enables you to reuse that behavior in multiple controls (your single control and your table view).
See Control and Cell Programming Topics for more info.
Apple added view-based table views in Lion, so you should be able do this natively with NSTableView, now.
(You still can't put an NSView in an NSCell—that wouldn't make sense. But you can have views instead of cells in a table view.)

Resources