How do I add custom cell in NSBrowser?

229 Views Asked by At

I need to add a custom cell that will have a checkbox i.e. NSButton and an NSImageCell.

I searched and found I need to override NSBrowserCell to achieve this, but the delegate method doesn't return any NSView or NSCell as it does in NSTableView.

The delegate method reads like this:

- (void)browser:(NSBrowser *)sender
willDisplayCell:(NSImageCell *)cell
          atRow:(NSInteger)row
         column:(NSInteger)column{

    NSBrowserCell *bcell = [[NSBrowserCell alloc] initImageCell:nil];
    //    cell = bcell;

}

It is obvious that I can not return the cell, then how do I update the cell?

enter image description here

1

There are 1 best solutions below

2
On

The cell class of a NSBrowser can be changed by setting

@property(strong) id cellPrototype;

The prototype NSCell for displaying items in the matrices in the columns of the browser. The prototype NSCell instance is copied to display items in the matrices of the browser.

or with

- (void)setCellClass:(Class)factoryId;

Sets the class of the cell to be used by the matrices in the columns of the browser. This method creates an instance of the class and sets cellPrototype.