Question

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;
    }
}
Was it helpful?

Solution

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

OTHER TIPS

  • -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (noResults){

    // return NSTableCellView height here;

    }else{

    // return SearchTableCell height here;

    }

}

Hope this helps you.

For a view based NSOutlineView, implement the delegate method outlineView:heightOfRowByItem: to return the desired row height.

To avoid constants within your code, consider determining the height from the associated view:

- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
    NSView* view = [self outlineView:outlineView viewForTableColumn:nil item:item];
    return (view ? NSHeight(view.frame) : outlineView.rowHeight);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top