Vikas Bansal
Vikas Bansal

Reputation: 11790

NSTable: How to get cell type of column?

Is it possible to get NSTable's column datatype e.g. ImageCell, TextCell

Reason

I have created a function that adds sorting to all columns of an NSTable

-(void)addSortingIdentifier:(NSTableView *)table
{
    for (NSTableColumn *tableColumn in table.tableColumns ) {

        ///if column is image cell type then do't go ahead....

        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:tableColumn.identifier ascending:YES selector:@selector(compare:)];
        [tableColumn setSortDescriptorPrototype:sortDescriptor];
    }

    table.allowsColumnSelection = NO;
}

Suppose there is a Image Cell type of column in the NSTable then it will add sorting to it as well.

If user is clicking the column header of image cell type then the sorting of whole NSTable is stopping to work.

Solution

I want to make a check in the for loop that if the column type is image cell then do not apply sorting to it.

Problem

How to check the type of column?

Upvotes: 0

Views: 74

Answers (1)

Vikas Bansal
Vikas Bansal

Reputation: 11790

Here is the flag that You can apply if you want to avoid applying sorting on NSImageCell

    Class theClass = NSClassFromString(@"NSImageCell"); //getting the class type
    if([[tblClm dataCell] isKindOfClass:theClass]) /// do not apply sorting on image cell class
    {
        continue;
    }

EDIT

An easy way to compare class type suggested by Willeke

if([[tblClm dataCell] isKindOfClass:[NSImageCell class]])
....

Upvotes: 1

Related Questions