1

ごきげんよう!

カスタム ビューをセル (NSTableCellView クラス) として持つビュー ベースの NSTableView があります。カスタムセル内に NSTextField があります。

NSTextField 内に 3 行のテキストを表示する必要があり、セルのコンテンツをクリックした後、全文に収まるように拡大する必要があります。つまり、クリックで NSTextField の高さと NSCTableCellView の高さをインクリメントする必要があります。

アルゴリズムは次のとおりです。

  1. NSTableCellView のクリックを処理する
  2. NSTextField と NSTableCellView の新しいサイズを計算する
  3. IBOutlet を介して NSTextField に FrameSize を設定する
  4. 新しい NSTableCellView の高さの値をクラスに保存し、通知センターから関数「RowHeightChanged」を呼び出します
  5. クラス値から新しい行の高さを設定

これはコードスニペットです: (私はいくつかの役に立たないものを消去しました)

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

NSTableView デリゲート:

@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

問題は、NSTextField をクリックすると、フレームが 2 秒間だけ大きくなり、初期サイズに戻った後、セルのプロパティの高さを設定するアニメーションが開始されることです。結果 - セルの高さは上がっていますが、NSTextField はありません。アニメーションを無効にしようとしましたが、結果はありません。どうすれば修正できますか?

私の英語をお詫びします:)

4

0 に答える 0