Cocoa 是否自动调整NSTableView的列大小以适应内容?
如何使NSTableView自动调整其列的大小,使每列中的所有内容都可见而不被截断?尝试以下方法:-Cocoa 是否自动调整NSTableView的列大小以适应内容?,cocoa,nstableview,Cocoa,Nstableview,如何使NSTableView自动调整其列的大小,使每列中的所有内容都可见而不被截断?尝试以下方法:- CGFloat oldWidth =0.0; for (i=0; i<[[arrCont arrangedObjects]count]; i++) { for (j=0;j<[[tableView tableColumns]count]; j++) { NSCell *dataCell=[tableView preparedCellAtColumn:j
CGFloat oldWidth =0.0;
for (i=0; i<[[arrCont arrangedObjects]count]; i++)
{
for (j=0;j<[[tableView tableColumns]count]; j++)
{
NSCell *dataCell=[tableView preparedCellAtColumn:j row:i];
CGFloat newWidth=[dataCell cellSize].width;
if (newWidth > oldWidth)
{
oldWidth=newWidth;
}
[[[tableView tableColumns] objectAtIndex:j] setWidth:newWidth];
}
}
这不符合预期。对于基于视图的表视图,这会将列的大小调整为IB中指定的宽度。对于基于单元格的表视图,有时会调整某些列的大小,即在多次执行此代码后,十列中约有三列已调整为最佳宽度。我将在今天晚些时候对此进行调试…请立即尝试此操作这些行需要更改NSCell*dataCell=[tableView preparedCellAtColumn:j行:I];