Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何使用NSTextField右键设置NSTableCellView的高度?_Macos_Cocoa_Nstableview_Nstablecolumn - Fatal编程技术网

Macos 如何使用NSTextField右键设置NSTableCellView的高度?

Macos 如何使用NSTextField右键设置NSTableCellView的高度?,macos,cocoa,nstableview,nstablecolumn,Macos,Cocoa,Nstableview,Nstablecolumn,欢迎 我有一个基于视图的NSTableView,自定义视图作为单元格(NSTableCellView类)。 自定义单元格中没有NSTextField 我需要在NSTextField中显示3行文本,单击单元格内容后,内容必须增长到适合全文。 所以,我需要通过单击来增加NSTextField的高度和NSCTableCellView的高度 Alghoritm是: 在NSTableCellView上单击句柄 计算NSTextField和NSTableCellView的新大小 通过IBOutlet将Fra

欢迎

我有一个基于视图的NSTableView,自定义视图作为单元格(NSTableCellView类)。 自定义单元格中没有NSTextField

我需要在NSTextField中显示3行文本,单击单元格内容后,内容必须增长到适合全文。 所以,我需要通过单击来增加NSTextField的高度和NSCTableCellView的高度

Alghoritm是:

  • 在NSTableCellView上单击句柄
  • 计算NSTextField和NSTableCellView的新大小
  • 通过IBOutlet将FrameSize设置为NSTextField
  • 在类中存储新的NSTableCellView高度值,并通过通知中心调用函数“RowHeightChanged”
  • 从类值设置新行高度
  • 这是一段代码片段:(我删除了一些无用的东西)

    TickCellTableView:

        @implementation TickCellTableView
    
        // Other Constants
        @synthesize textFieldInitHeight = _textFieldInitHeight;
        @synthesize rowHeight           = _rowHeight;
        @synthesize rowIndex            = _rowIndex;
    
        - (void)mouseDown:(NSEvent *)theEvent {
    
            if (![self.superview isKindOfClass:[NSTableCellView class]])
                [super mouseDown:theEvent];
    
    
            CGFloat TextFieldFitHeight = [self getHeightForStringDrawing: self.textField.stringValue
                                                              withFont:[self.textField font]
                                                          forTextWidth:[self.textField frame].size.width + 10.0];
    
            if ([self.textField frame].size.height < TextFieldFitHeight)
            {
                NSSize size = [self.textField frame].size;
                size.height = TextFieldFitHeight;
    
                [self.textField setFrameSize:size];        
    
                self.rowHeight = [self frame].size.height + (TextFieldFitHeight - _textFieldInitHeight);
    
                [[NSNotificationCenter defaultCenter] postNotificationName:@"RowHeightChanged"
    
    
                                                                       object:self.rowIndex];
                }
            }
    @end
    
    问题是,当我单击NSTextField时,它的帧仅增长了第二帧并返回到init size,然后启动动画以设置单元格的属性高度。 结果-单元格高度增加,但NSTextField无。我试图禁用动画-没有结果。我怎样才能解决这个问题


    请原谅我的英语:)

    你有没有试过这样做?我也有同样的问题!:)
    @implementation DisplayTicksView
    
    - (void)awakeFromNib
    {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(RowHeightChanged:)
                                                     name: @"RowHeightChanged"
                                                   object:nil];    
     }
    
    -(void)RowHeightChanged:(NSNotification *)notification
    {        
        NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:[notification.object integerValue]];
    
        [tableView noteHeightOfRowsWithIndexesChanged:indexSet];
    }
    
    
    - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
    {
        return [ticksArray count];
    }
    
    
    @end