美文网首页
NSTableView在MacOS11.0以上的系统自动增加边距

NSTableView在MacOS11.0以上的系统自动增加边距

作者: devileatapple | 来源:发表于2021-02-20 17:30 被阅读0次

    NSTableView在MACOS Big Sur(11.0)之后的显示有点异常,悄咪咪的增加了左右以及上下间距。要解决这个问题:

    1.首先设置NSTableView的style;

        if(@available(macOS11.0, *)) {

            _tableView.style=NSTableViewStylePlain;

        }else{

            // Fallback on earlier versions

        }

    2.设置之后,上下间距消失,但左右还有6pt的间距

    在wiki里看改变,发现需要自定义Cell的背景view,也就是NSTableRowView,把对应的cell添加到这个rowview里。实现下面的方法,

    - (NSTableRowView *)tableView:(NSTableView *) tableView  rowViewForRow: (NSInteger) row {

                ProductTableRowView *view= [[ProductTableRowView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.lt_w, kProductCellH)];//自定义NSTableRowView

       ProductCell*cell = [tableViewmakeViewWithIdentifier:@"ProductCellID"owner:self];

        if(!cell) {

            cell = [[ProductCell alloc]initWithFrame:NSMakeRect(0,0,kLeftW,kProductCellH)];

        }

        ProductMO *mo = [_datas objectAtIdx:row];

        [cell bindData:mo];

        [view addSubview:cell];

        return view;

    }

    取消实现cell的方法

    - (NSView*)tableView:(NSTableView*)tableViewviewForTableColumn:(NSTableColumn*)tableColumnrow:(NSInteger)row {
        retrun nil;

    }

    暂时这么处理能解决边距的问题,仅提供思路,有什么问题可以留言大家一起探讨。

    参考链接:

    https://developer.apple.com/forums/thread/666341

    https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#Table_Views

    相关文章

      网友评论

          本文标题:NSTableView在MacOS11.0以上的系统自动增加边距

          本文链接:https://www.haomeiwen.com/subject/pkrxfltx.html