Search code examples
objective-cxcodemacosnstableviewnstablecellview

Two NSTableCellView with different sizes appearing with the same size


Here are my 2 NSTableCellViews:
enter image description here

The 1st is bigger than the 2nd (this one is used when the user is searching the tableview and there are no results) but when i run my app the 2nd gets the size of the 1st:
enter image description here

Why is this happening? Here's my part of the code

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
    if (noResults){
        return 1; 
    }else{
        return [array count];
    }
}

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    if (noResults){
        NSTableCellView *result = [tableView makeViewWithIdentifier:@"NoResults" owner:self];
        result.textField.stringValue = [NSString stringWithFormat:@"No results for \"%@\"", _searchTXT.stringValue];
        return result;
    }else{ 
        SearchTableCell *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
        result.textField.stringValue = @"Name";
        result.textField2.stringValue = @"Last Name";
        return result;
    }
}

Solution

  • You need to implement the tableView:heightForRowAtIndexPath: method. Otherwise the cell will all be the height of the table views rowHeight property.