How to create a header view for NSCollectionView - macos

I need to set a header view for my NSCollection view. When I researched I found that NSCollection view don't support a default header view like NSTableView. I need a header almost like the one used in skype. ie. apart from displaying just a title, I may need to perform some actions upon clicking header corresponding to a column. for eg. Sort by name upon clicking 'Name' column.
What is the best way to implement this if I subclass and create my own header view? Which view should I subClass to get both, the look and feel of NSTableview header and the clickable properties like that of NSButton?

Related

Hide Group header in Grouped ListView

I'm displaying a GroupedList view, and have both enabled the group header and jumplist. I've tried to hide the Group header, but so far with no luck. This property I want to hide is GroupDisplayBinding. If I don't set it, a default of ToString for my Item is displayed. I just want it gone, as a regular list only with the jump option enabled.
A little update: I searched some samples and what I want is a TableView with and indexed list as displayed here: https://developer.xamarin.com/guides/ios/user_interface/tables/part_2_-_populating_a_table_with_data/#Adding_an_Index
Best regards
Xamarin.Forms listview allows you to specify your own layout for the listview group via GroupHeaderTemplate property. You can use this layout to keep the header content empty.
Have a look at Customizing Listview Grouping
If you want to define the group header layout in code you will have to create a new subclass of ViewCell and build the layout. See an example at Enhancing Xamarin.Forms ListView with Grouping Headers

NSCollectionView Delegate Method on Select Header

The latest update to NSCollectionView allows the delegate to detect the selection of items with
- (NSSet<NSIndexPath *>*)collectionView:(NSCollectionView*)collectionView shouldSelectItemsAtIndexPaths:(NSSet<NSIndexPath*>*)indexPaths
and
- (void)collectionView:(NSCollectionView*)collectionView didSelectItemsAtIndexPaths:(NSSet<NSIndexPath*>*)indexPaths
, among others.
However, insofar as I can tell, these methods only detect the selection of NSCollectionViewItem objects, and not any present header or footer views.
Are there any delegate methods to detect the selection of the header and/or footer views? If not, what is the best way to implement this detection?
Indeed these delegate methods are only for selecting items. If you want to do something when the header of footer view is clicked, you can add a gesture recognizer to those views yourself and hook it up to an IBAction on your controller.

Using NSArrayController to bind model objects to an inspector view, how to catch special cases like empty and multiple selections?

I have inspector view and because it contains a lot of UI I want to explore cocoa bindings to connect it to the model. The inspector view will update depending on the currently selected object in an outline view and the inspector view displays controls to alter properties (like colour, name, shape etc.) that can be changed.
This works well when only one row in the outline view is selected because the view has a one-to-one relationship with the model object. However, there are two special cases that I want to be able to catch:
Empty selection
If no items in the outline view are selected I want to display a special "No items selected view" placeholder view.
Multiple selection
If multiple items are selected I can either display a "Multiple items selected view" placeholder view or I can decide to let the changes apply globally to all selected model objects.
My question is how can these special cases be caught when using bindings? Moreover, how can I do behaviour "A" when there is an empty selection and behaviour "B" when there is a multiple section. This sort of thing is trivial when using target/action because you can just code the logic into the action method.
Bindings seem great when propagating changes to values but I'm unsure how to go about implementing bindings that require different decisions based on current selection state.

Marionette Layout object to render tab content

I have a region in which I need to have a tabbed view (simple) however if I want the tab content to be differently layout - not sure how to achieve it. I can create different layout with multiple region and corresponding view, but how do I attach this to tab content, given that applyout can only be attached to region? Or can this be attached to one of the div of tab-content using $el?? Need some pointers.
Not sure I entirely understand your question.. But here goes.
I have implemented a navigation component where I can pass a tabsCollection and region. It will set up a region for the content and a list of tabs above it. When a tab is clicked it will fire the callback on the model in the tabsCollection which can be used to display what ever content you want.
There are more complex ways to handle this to allow for caching of a tabs content. But basically using a Backbone collection for the tabs with their own function for displaying content will do the trick.

How to get the stringValue of a Text Field Cell inside a Table View after editing the cell?

I have a standard Table View with the default settings inside my main nib. I use an Array Controller and Bindings for dealing with the data that the table view should show to the users. I already achieved that the "add" button inserts the new row and sets the first column to editing mode so the users can type their text immediately. My problem is i can't detect when the editing is over and i should save the new values. I couldn't find any delegate method and/or any notification for this purpose. I searched the internet and i couldn't find anything useful. I'm not even sure that i'm doing it right, i didn't add any specific thing, i just use the standard double click editing that the table view offers for each cell.
Any help is much appreciated.
Thanks in advance!
If you have everything hooked up with bindings, you shouldn't need to save the data until you exit the program. When the array controller's add: method is called, the new record is added to the controller's arranged objects, and the array holding your data is also updated. So, you only need to save the array when your app closes.
However, if you wish to save the data after every edit, you can detect the end of the editing with the delegate method controlTextDidEndEditing:. You will get a notification after each column is finished editing (make sure to make the class where you implement this method the delegate of the table view).

Resources