1

これが私の2つのNSTableCellViewsです。
ここに画像の説明を入力してください

1番目は2番目よりも大きいです(これは、ユーザーがテーブルビューを検索していて結果がない場合に使用されます)が、アプリを実行すると、2番目は1番目のサイズになります。
ここに画像の説明を入力してください

なぜこうなった?これが私のコードの一部です

- (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;
    }
}
4

3 に答える 3

2

tableView:heightForRowAtIndexPath:メソッドを実装する必要があります。それ以外の場合、セルはすべてテーブルビューのrowHeightプロパティの高さになります。

于 2012-10-18T22:59:54.540 に答える
1
  • -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if(noResults){

    //ここにNSTableCellViewの高さを返します;

    }そうしないと{

    //ここにSea​​rchTableCellの高さを返します;

    }

}

これがお役に立てば幸いです。

于 2012-10-19T05:58:02.123 に答える
1

ビューベースのNSOutlineViewの場合、デリゲートメソッドを実装してoutlineView:heightOfRowByItem:、目的の行の高さを返します。

コード内の定数を回避するには、関連するビューから高さを決定することを検討してください。

- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
    NSView* view = [self outlineView:outlineView viewForTableColumn:nil item:item];
    return (view ? NSHeight(view.frame) : outlineView.rowHeight);
}
于 2014-02-04T15:19:01.513 に答える