Macos OSX:NSTableView包含多行的单元格?
有多行的Macos OSX:NSTableView包含多行的单元格?,macos,cocoa,nstableview,Macos,Cocoa,Nstableview,有多行的NSTableView单元格的最佳方式是什么?比如说5或6 我知道这个问题和答案“”,但基于这个答案,OSX上的机制似乎不同: 在NSTableView的委托中: @interface MenuDelegate () @property (nonatomic, weak) NSArrayController * theArrayController ; @property (nonatomic, strong) NSTextFieldCell * anExtraTextFieldCe
NSTableView
单元格的最佳方式是什么?比如说5或6
我知道这个问题和答案“”,但基于这个答案,OSX上的机制似乎不同:
在NSTableView的委托中
:
@interface MenuDelegate ()
@property (nonatomic, weak) NSArrayController * theArrayController ;
@property (nonatomic, strong) NSTextFieldCell * anExtraTextFieldCell ;
@property (nonatomic) NSRect tallRect ;
@end
@implementation MenuDelegate
#pragma mark - Initialisations
- (id)initwithArrayController:(NSArrayController *)theArrayController;
{
self = [super init] ;
if (self)
{
self.theArrayController = theArrayController ;
self.anExtraTextFieldCell = [[NSTextFieldCell alloc] init] ;
}
return self ;
}
- (CGFloat) tableView:(NSTableView *)tableView
heightOfRow:(NSInteger)row {
if (!self.tallRect.size.width)
{
NSTableColumn * firstColum = tableView.tableColumns[0] ;
self.tallRect = NSMakeRect(0, 0, firstColum.width, CGFLOAT_MAX);
}
// Access the content of the cell.
NSString * content = [self.theArrayController.arrangedObjects[row] valueForKey:@"title"] ;
self.anExtraTextFieldCell.stringValue = content ;
CGFloat result = [self.anExtraTextFieldCell cellSizeForBounds:self.tallRect].height + 5;
if (result < [tableView rowHeight])
{
result = [tableView rowHeight] ;
}
return result ;
}
@接口菜单legate()
@属性(非原子,弱)NSArrayController*ArrayController;
@属性(非原子,强)NSTextFieldCell*anExtraTextFieldCell;
@属性(非原子)NSRect tallRect;
@结束
@实现菜单Legate
#pragma标记-初始化
-(id)初始化阵列控制器:(NSArrayController*)阵列控制器;
{
self=[super init];
如果(自我)
{
self.theArrayController=ArrayController;
self.anExtraTextFieldCell=[[NSTextFieldCell alloc]init];
}
回归自我;
}
-(CGFloat)表格视图:(NSTableView*)表格视图
高度:(NSInteger)行{
如果(!self.tallRect.size.width)
{
NSTableColumn*firstColumn=tableView.tableColumns[0];
self.tallRect=NSMakeRect(0,0,firstcolumn.width,CGFLOAT_MAX);
}
//访问单元格的内容。
NSString*content=[self.theArrayController.arrangedObjects[row]valueForKey:@“title”];
self.anExtraTextFieldCell.stringValue=内容;
CGFloat结果=[self.anExtrateXtfieldCellSizeForBounds:self.tallRect].height+5;
如果(结果<[tableView行高])
{
结果=[tableView行高];
}
返回结果;
}
您能更具体地说明您遇到的问题吗?如果使用基于视图的NSTableView,则可以在Interface Builder中创建具有任意子视图排列的NStableCellView,这与在iOS上可以执行的操作非常类似。这包括多行文本字段,或多行排列的单行文本字段。我想避免使用基于视图的表视图的痛苦…基于视图的表视图比基于单元格的表视图更易于自定义。使用基于单元格的表视图并不能避免痛苦。。。