I am new to cocoa. I will need to implement an NSoutlineview for 10.6 OS X and above. I have hierarchy of data which must be shown in the form of outlineview. The cell for outline view must contain an image and text. Could some body please suggest on how to go a head with this?
thanks
an outlineview is basically just a tableview so all tutorials for NSTableView apply to it
only the dataSource methods differ
so: http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/
and combine it will a tutorial of a cell based outline. e.g. http://devcry.heiho.net/2012/02/treeview-in-cocoa-nsoutlineview.html
For your best practice you can refer this sample code Sourceview
To customize your text you need to set your cell as ImageAndText cell as shown in that samplecode
Related
I'm trying to build a UI which look like this:
I'm using a storyboard with Xcode but I don't know how to start. I think a need different view in the window to manage button, text and tree but I don't know I to do it. I have try to use a split view but it gave me only 2 views instead of 3.
Any help in Cocoa and storyboard is welcome.
Thanks
Can't see where you'd want to use an NSSplitView but the UI you're attemting to create is trivial -
A plain NSWindow with the toolbar items configured as per your screenshot.
An NSOutlineView for the tree view with the three columns,
the content border of the window sized accordingly to make room for the label you intend to put at the bottom of the window.
As mentioned in the comments one way to populate the outline view would be to use an NSTreeController and Cocoa bindings. That's probably the only slightly more complicated bit about this UI..
What is the main difference between cell based and view based tableviews in Cocoa.
The understanding I have is cell based tableviews are basically used for displaying strings and view based are for custom cells.User events such as dragging rows, selection etc can be handled in view based.
cell based tableviews use objectValueForTableColumn: method and view based tables use viewForTableColumn: method.
Is my understanding correct?. Or is any other design concerns between these table views. When to go for cell based and when to go for view based.
Thanks in advance
short answer:
A cell can contain only one UI element like a text cell, image view cell, button cell and a few more. The customization ability is quite poor.
A view can contain multiple UI elements as well as other views. The customization ability is almost infinite.
Apple recommends to use always view based table views
NSCell is a lighter weight object and was a solution when it was a concern to have too many NSView objects.
Think more than a decade ago.
Cells are deprecated.
Use views.
Is there a way I can make this view using Cocoa.
Also it needs to be resizable meaning the width should be depending on the text length? Thank you in advance
Yes, you can. Look at the NSPopover Class Reference.
what I want to do is,
I am using UICollectionView to show my stuff.
What I want is, the stuff that I want to show is coming from server,
It may be in single line or some may be multiple.
I wanted to show the cell frame of UICollectionView differently.
Means If data is big then bigger frame of UICollectionViewcell
and if data is less then smaller frame of UICollectionViewcell.
I tried a lot,
but I am succeed only in having fixed size of frame for UICollectionViewcell
How to achieve different frame for each cell according to need.
Is it possible....?
#note :- I am not using any xib.
All is done programatically.
It seem like you are getting UICollectionView wrongly.
Let me say in short You are not suppose to set frame but you need to implement your own UICollectionViewLayout.
By default UICollectionView use UICollectionViewFlowLayout. Which add cell one by one.
But UICollectionView is very power full UI component than that. To open its true power you have to understand UICollectionViewLayout.
Here are some good example of that :
RFQUILTLAYOUT
CHTCollectionViewWaterfallLayout
CCHexagonFlowLayout
MSCollectionViewCalendarLayout
If you want to learn how to create your ow than have a look at following link:
Creating Custom Layouts
Custom Layouts: A Worked Example
Implementing UICollectionViewLayout
UICollectionView custom layout tutorial
A Springboard-Like Layout With the UICollectionView Class
If you need to know overview of how UICollectionView work than read : NSHipster:UICollection​View
One in depth look in Custom Collection View Layouts : objc : Custom Collection View Layouts
I hope I get u correctly. And this will lead you to right direction.
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.)