NSView Autolayout Used as Cell for NSTableView

I'm trying to create NSTableViewsomething similar to how Things makes its layout. Things 2.0 - (c) CulturedCode

I guess they use NSTableViewwith a custom pattern NSTableCell- or maybe that NSSegmentedControl. I'm trying to go down the route NSTableCell. I tried to subclass NSTableCellViewand draw a custom cell (all this in the init method for testing);

- (id)init {
    self = [super init];
    if (self) {
        _checkbox = [[NSButton alloc] init];
        [_checkbox setButtonType:NSSwitchButton];

        _textview = [[NSTextView alloc] init];

        [self addSubview:_checkbox];
        [self addSubview:_textview];

        [self setTranslatesAutoresizingMaskIntoConstraints:NO];
        NSDictionary *views = NSDictionaryOfVariableBindings(_checkbox, _textview);

        [self addConstraints:
                [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_checkbox]-[_textview]|"
                                                        options:0
                                                        metrics:nil
                                                          views:views]];
    }

    return self;
}
@end

It seems pretty straightforward, but it actually doesn't work. I get errors regarding restrictions that cannot be met. Is it not possible to use autostart inside a subclass NSTableCellView?

+4
source share
1

, :

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
NSTableCellView *rowView = [self.tableView makeViewWithIdentifier: RVIssueSelectionTableRowViewContentKey owner: self];

[rowView setObjectValue: yourDataObject]; // or update your cell with the according data the way you prefer
[rowView setNeedsLayout: YES];
[rowView layoutSubtreeIfNeeded];

return [rowView fittingSize].height;
}

, , . , . SO, ( , ). , x ( ). , . .

+3

All Articles