NSTableView的应用详解 一、引言 和iOS开发中的UITableView有很大差别,NSTableView并非是一个可滚动的列表视图,其是一个不可滚动、支持多列多行的原始列表视图。若要使NSTableView支持滚动,通常会将其嵌套入NSScrollView控件中。与UITableView类似,NSTableView的数据也是用过DataSource代理来提供,通过Delegate代理来进行表格视图的定制化。在OS X v10.6版本之前,NSTableView中行数据载体视图必须是NSCell的子类,之后版本的OS X支持开发者创建基于View的TableView视图,同样也支持基于Cell的TabelView视图,在开发者,我们可以根据实际需求选择。
二、构建一个简单的列表视图 首先新建一个测试工程,在ViewController.m文件中编写如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #import "ViewController.h" @interface ViewController ()<NSTableViewDelegate ,NSTableViewDataSource >@end @implementation ViewController { NSTableView * _tableView; NSMutableArray * _dataArray; } - (void )viewDidLoad { [super viewDidLoad]; _dataArray = [NSMutableArray array]; for (int i=0 ; i<20 ; i++) { [_dataArray addObject:[NSString stringWithFormat:@"%d行数据" ,i]]; } NSScrollView * scrollView = [[NSScrollView alloc] init]; scrollView.hasVerticalScroller = YES ; scrollView.frame = self .view.bounds; [self .view addSubview:scrollView]; _tableView = [[NSTableView alloc]initWithFrame:self .view.bounds]; NSTableColumn * column = [[NSTableColumn alloc]initWithIdentifier:@"test" ]; [_tableView addTableColumn:column]; _tableView.delegate = self ; _tableView.dataSource = self ; [_tableView reloadData]; scrollView.contentView.documentView = _tableView; } -(NSInteger )numberOfRowsInTableView:(NSTableView *)tableView{ return _dataArray.count; } -(id )tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger )row{ return _dataArray[row]; } @end
运行工程效果如下图:
这是一个最简单的TableView示例,但是细读代码,麻雀虽小五脏俱全。首先NSTableView中的列是由NSTableColumn类描述的。一个列表可以有多个列。也正如前面所说,numberOfRowsInTableView方法为数据源代理必须实现的方法,其中需要返回列表的行数。objectValueForTableColumn方法则是基于Cell的TableView必须实现的方法,其中需要返回每个列表行所填充的数据。
三、关于NSTableColume的探究 NSTableColume简单理解就是一列,其中可以进行此列样式的相关设置,NSTableColumn类中常用属性解析如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 - (instancetype )initWithIdentifier:(NSString *)identifier; @property (copy ) NSString *identifier;@property (nullable , assign ) NSTableView *tableView;@property CGFloat width;@property CGFloat minWidth;@property CGFloat maxWidth;@property (copy ) NSString *title;@property (strong ) __kindof NSTableHeaderCell *headerCell;@property (getter =isEditable) BOOL editable;- (void )sizeToFit; @property (nullable , copy ) NSSortDescriptor *sortDescriptorPrototype;@property NSTableColumnResizingOptions resizingMask;@property (nullable , copy ) NSString *headerToolTip;@property (getter =isHidden) BOOL hidden;@property (strong ) id dataCell;- (id )dataCellForRow:(NSInteger )row;
四、Cell-Base:基于Cell的TableView视图 Cell-Base是OS X早起版本中常用的构造TabelView的方式,其中每一行的数据载体都必须是NSCell的子类。如本文开头的示例代码,Cell-Base的TableView必须实现的两个协议方法是numberOfRowsInTableView和objectValueForTableColumn方法,第一个方法设置列表行数,第2个方法设置每个数据载体对应的具体数据。需要注意,如果只实现这两个方法,则NSTableView会自动从列对象NSTableColume中取具体的行视图,通过dataCellForRow方法。当objectValueForTableColumn方法将每个行具体的数据返回后,会调用cell的setObjectValue方法(因此如果要自定义cell,必须实现这个方法)。如果我们要对Cell的渲染进行一些定制,可以在如下方法中实现:
1 2 - (void )tableView:(NSTableView *)tableView willDisplayCell:(id )cell forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row;
实现下面的方法可以返回一个自定义的Cell,如果实现了这个方法,则TableView不会再从NSTableColumn对象中拿Cell实例:
1 2 3 4 5 6 - (nullable NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row;
其他方法的实例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 #import "ViewController.h" #import "MyCell.h" @interface ViewController ()<NSTableViewDelegate ,NSTableViewDataSource >@end @implementation ViewController { NSTableView * _tableView; NSMutableArray * _dataArray; } - (void )viewDidLoad { [super viewDidLoad]; _dataArray = [NSMutableArray array]; for (int i=0 ; i<20 ; i++) { [_dataArray addObject:[NSString stringWithFormat:@"%d行数据" ,i]]; } NSScrollView * scrollView = [[NSScrollView alloc] init]; scrollView.hasVerticalScroller = YES ; scrollView.frame = self .view.bounds; [self .view addSubview:scrollView]; _tableView = [[NSTableView alloc]initWithFrame:self .view.bounds]; NSTableColumn * column = [[NSTableColumn alloc]initWithIdentifier:@"test" ]; NSTableColumn * column2 = [[NSTableColumn alloc]initWithIdentifier:@"test2" ]; column2.width = 100 ; column2.minWidth = 100 ; column2.maxWidth = 100 ; column2.title = @"数据" ; column2.editable = YES ; column2.headerToolTip = @"提示" ; column2.hidden=NO ; column2.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:NO ]; column.resizingMask =NSTableColumnUserResizingMask ; [_tableView addTableColumn:column]; [_tableView addTableColumn:column2]; _tableView.delegate = self ; _tableView.dataSource = self ; scrollView.contentView.documentView = _tableView; } -(NSInteger )numberOfRowsInTableView:(NSTableView *)tableView{ return _dataArray.count; } -(id )tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger )row{ return _dataArray[row]; } - (void )tableView:(NSTableView *)tableView setObjectValue:(nullable id )object forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ NSLog (@"%@" ,object); _dataArray[row] = object; } - (void )tableView:(NSTableView *)tableView willDisplayCell:(id )cell forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ NSTextFieldCell * _cell = cell; _cell.textColor = [NSColor redColor]; } - (BOOL )tableView:(NSTableView *)tableView shouldEditTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ return YES ; } - (NSString *)tableView:(NSTableView *)tableView toolTipForCell:(NSCell *)cell rect:(NSRectPointer )rect tableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row mouseLocation:(NSPoint )mouseLocation{ return @"tip" ; } - (BOOL )tableView:(NSTableView *)tableView shouldShowCellExpansionForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ return YES ; } - (BOOL )tableView:(NSTableView *)tableView shouldTrackCell:(NSCell *)cell forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ return YES ; } - (nullable NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ if (tableColumn!=nil ) { MyCell * cell = [[MyCell alloc]init]; return cell; } return nil ; } -(CGFloat )tableView:(NSTableView *)tableView heightOfRow:(NSInteger )row{ return 30 ; } -(void )tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray <NSSortDescriptor *> *)oldDescriptors{ NSLog (@"%@" ,oldDescriptors[0 ]); } @end
五、View-Base:基于View的TableView视图 基于View-Base的TableView要比基于Cell的TableView更加灵活,其中每行数据载体可以是任意NSView的子类。代码示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 #import "ViewController.h" #import "MyCell.h" #import "TableRow.h" @interface ViewController ()<NSTableViewDelegate ,NSTableViewDataSource >@end @implementation ViewController { NSTableView * _tableView; NSMutableArray * _dataArray; } - (void )viewDidLoad { [super viewDidLoad]; _dataArray = [NSMutableArray array]; for (int i=0 ; i<20 ; i++) { [_dataArray addObject:[NSString stringWithFormat:@"%d行数据" ,i]]; } NSScrollView * scrollView = [[NSScrollView alloc] init]; scrollView.hasVerticalScroller = YES ; scrollView.frame = self .view.bounds; [self .view addSubview:scrollView]; _tableView = [[NSTableView alloc]initWithFrame:self .view.bounds]; NSTableColumn * column = [[NSTableColumn alloc]initWithIdentifier:@"test" ]; NSTableColumn * column2 = [[NSTableColumn alloc]initWithIdentifier:@"test2" ]; column2.width = 100 ; column2.minWidth = 100 ; column2.maxWidth = 100 ; column2.title = @"数据" ; column2.editable = YES ; column2.headerToolTip = @"提示" ; column2.hidden=NO ; column2.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:NO ]; column.resizingMask =NSTableColumnUserResizingMask ; _tableView.delegate = self ; _tableView.dataSource = self ; [_tableView addTableColumn:column]; [_tableView addTableColumn:column2]; scrollView.contentView.documentView = _tableView; } -(NSInteger )numberOfRowsInTableView:(NSTableView *)tableView{ return _dataArray.count; } - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row{ NSTextField * view = [tableView makeViewWithIdentifier:@"cellId" owner:self ]; if (view==nil ) { view = [[NSTextField alloc]initWithFrame:CGRectMake (0 , 0 , 100 , 30 )]; view.backgroundColor = [NSColor clearColor]; view.identifier = @"cellId" ; } return view; } - (nullable NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger )row{ TableRow * rowView = [[TableRow alloc]init]; return rowView; } - (void )tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger )row{ NSLog (@"add" ); } - (void )tableView:(NSTableView *)tableView didRemoveRowView:(NSTableRowView *)rowView forRow:(NSInteger )row{ NSLog (@"remove" ); } @end
上面代码中用到了TableRow类,其实它是一个自定义的继承自NSTableRowView的类,实现如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #import "TablerRow.h" @implementation TablerRow -(void )drawSelectionInRect:(NSRect )dirtyRect{ NSRect selectionRect = NSInsetRect (self .bounds, 5.5 , 5.5 ); [[NSColor colorWithCalibratedWhite:.72 alpha:1.0 ] setStroke]; [[NSColor colorWithCalibratedWhite:.82 alpha:1.0 ] setFill]; NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:10 yRadius:10 ]; [selectionPath fill]; [selectionPath stroke]; } -(void )drawBackgroundInRect:(NSRect )dirtyRect{ [super drawBackgroundInRect:dirtyRect]; [[NSColor greenColor]setFill]; NSRectFill (dirtyRect); } @end
关于NSTableRowView类我们下面来做具体介绍。
六、NSTableRowView解析 NSTableRowView用在View-Base的TableView中,其作为行容器存在。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 @property NSTableViewSelectionHighlightStyle selectionHighlightStyle;@property (getter =isEmphasized) BOOL emphasized;@property (getter =isGroupRowStyle) BOOL groupRowStyle;@property (getter =isSelected) BOOL selected;@property (getter =isPreviousRowSelected) BOOL previousRowSelected;@property (getter =isNextRowSelected) BOOL nextRowSelected;@property (getter =isFloating) BOOL floating;@property (getter =isTargetForDropOperation) BOOL targetForDropOperation;@property NSTableViewDraggingDestinationFeedbackStyle draggingDestinationFeedbackStyle;@property CGFloat indentationForDropOperation;@property (copy ) NSColor *backgroundColor;- (void )drawBackgroundInRect:(NSRect )dirtyRect; - (void )drawSelectionInRect:(NSRect )dirtyRect; - (void )drawSeparatorInRect:(NSRect )dirtyRect; - (void )drawDraggingDestinationFeedbackInRect:(NSRect )dirtyRect; @property (readonly ) NSInteger numberOfColumns;- (nullable id )viewAtColumn:(NSInteger )column;
七、来总结下NSTableViewDataSource协议 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 - (NSInteger )numberOfRowsInTableView:(NSTableView *)tableView; - (nullable id )tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (void )tableView:(NSTableView *)tableView setObjectValue:(nullable id )object forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (void )tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray <NSSortDescriptor *> *)oldDescriptors; - (nullable id <NSPasteboardWriting >)tableView:(NSTableView *)tableView pasteboardWriterForRow:(NSInteger )row; - (void )tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint )screenPoint forRowIndexes:(NSIndexSet *)rowIndexes NS_AVAILABLE_MAC (10 _7); - (void )tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint )screenPoint operation:(NSDragOperation )operation NS_AVAILABLE_MAC (10 _7); - (void )tableView:(NSTableView *)tableView updateDraggingItemsForDrag:(id <NSDraggingInfo >)draggingInfo NS_AVAILABLE_MAC (10 _7); - (BOOL )tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard; - (NSDragOperation )tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo >)info proposedRow:(NSInteger )row proposedDropOperation:(NSTableViewDropOperation )dropOperation; - (BOOL )tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo >)info row:(NSInteger )row dropOperation:(NSTableViewDropOperation )dropOperation; - (NSArray <NSString *> *)tableView:(NSTableView *)tableView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)indexSet;
八、来总结下NSTableViewDelegate协议 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (nullable NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger )row NS_AVAILABLE_MAC (10 _7); - (void )tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger )row; - (void )tableView:(NSTableView *)tableView didRemoveRowView:(NSTableRowView *)rowView forRow:(NSInteger )row; - (void )tableView:(NSTableView *)tableView willDisplayCell:(id )cell forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (BOOL )tableView:(NSTableView *)tableView shouldEditTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (NSString *)tableView:(NSTableView *)tableView toolTipForCell:(NSCell *)cell rect:(NSRectPointer )rect tableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row mouseLocation:(NSPoint )mouseLocation; - (BOOL )tableView:(NSTableView *)tableView shouldShowCellExpansionForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (BOOL )tableView:(NSTableView *)tableView shouldTrackCell:(NSCell *)cell forTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (nullable NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row; - (BOOL )selectionShouldChangeInTableView:(NSTableView *)tableView; - (BOOL )tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger )row; - (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes; - (BOOL )tableView:(NSTableView *)tableView shouldSelectTableColumn:(nullable NSTableColumn *)tableColumn; - (void )tableView:(NSTableView *)tableView mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn; - (void )tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn; - (void )tableView:(NSTableView *)tableView didDragTableColumn:(NSTableColumn *)tableColumn; - (CGFloat )tableView:(NSTableView *)tableView heightOfRow:(NSInteger )row; - (nullable NSString *)tableView:(NSTableView *)tableView typeSelectStringForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger )row NS_AVAILABLE_MAC (10 _5); - (NSInteger )tableView:(NSTableView *)tableView nextTypeSelectMatchFromRow:(NSInteger )startRow toRow:(NSInteger )endRow forString:(NSString *)searchString NS_AVAILABLE_MAC (10 _5); - (BOOL )tableView:(NSTableView *)tableView shouldTypeSelectForEvent:(NSEvent *)event withCurrentSearchString:(nullable NSString *)searchString NS_AVAILABLE_MAC (10 _5); - (BOOL )tableView:(NSTableView *)tableView isGroupRow:(NSInteger )row; - (CGFloat )tableView:(NSTableView *)tableView sizeToFitWidthOfColumn:(NSInteger )column; - (BOOL )tableView:(NSTableView *)tableView shouldReorderColumn:(NSInteger )columnIndex toColumn:(NSInteger )newColumnIndex; - (NSArray <NSTableViewRowAction *> *)tableView:(NSTableView *)tableView rowActionsForRow:(NSInteger )row edge:(NSTableRowActionEdge )edge NS_AVAILABLE_MAC (10 _11); - (void )tableViewSelectionDidChange:(NSNotification *)notification; - (void )tableViewColumnDidMove:(NSNotification *)notification; - (void )tableViewColumnDidResize:(NSNotification *)notification; - (void )tableViewSelectionIsChanging:(NSNotification *)notification;
九、NSTableView中常用的属性和方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 - (instancetype )initWithFrame:(NSRect )frameRect; - (nullable instancetype )initWithCoder:(NSCoder *)coder; @property (nullable , weak ) id <NSTableViewDataSource > dataSource;@property (nullable , weak ) id <NSTableViewDelegate > delegate;@property (nullable , strong ) NSTableHeaderView *headerView;@property (nullable , strong ) NSView *cornerView;@property BOOL allowsColumnReordering;@property BOOL allowsColumnResizing;@property NSTableViewColumnAutoresizingStyle columnAutoresizingStyle;@property NSTableViewGridLineStyle gridStyleMask;@property NSSize intercellSpacing;@property BOOL usesAlternatingRowBackgroundColors;@property (copy ) NSColor *backgroundColor;@property (copy ) NSColor *gridColor;@property NSTableViewRowSizeStyle rowSizeStyle;@property CGFloat rowHeight;@property (readonly , copy ) NSArray <NSTableColumn *> *tableColumns;@property (readonly ) NSInteger numberOfColumns;@property (readonly ) NSInteger numberOfRows;- (void )addTableColumn:(NSTableColumn *)tableColumn; - (void )removeTableColumn:(NSTableColumn *)tableColumn; - (void )moveColumn:(NSInteger )oldIndex toColumn:(NSInteger )newIndex; - (NSInteger )columnWithIdentifier:(NSString *)identifier; - (nullable NSTableColumn *)tableColumnWithIdentifier:(NSString *)identifier; - (void )scrollRowToVisible:(NSInteger )row; - (void )scrollColumnToVisible:(NSInteger )column; - (void )reloadData; - (void )reloadDataForRowIndexes:(NSIndexSet *)rowIndexes columnIndexes:(NSIndexSet *)columnIndexes; @property (readonly ) NSInteger editedColumn;@property (readonly ) NSInteger editedRow;@property (readonly ) NSInteger clickedColumn;@property (readonly ) NSInteger clickedRow;- (void )setIndicatorImage:(nullable NSImage *)image inTableColumn:(NSTableColumn *)tableColumn; - (nullable NSImage *)indicatorImageInTableColumn:(NSTableColumn *)tableColumn; @property BOOL verticalMotionCanBeginDrag;- (BOOL )canDragRowsWithIndexes:(NSIndexSet *)rowIndexes atPoint:(NSPoint )mouseDownPoint; - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray <NSTableColumn *> *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer )dragImageOffset; - (void )setDraggingSourceOperationMask:(NSDragOperation )mask forLocal:(BOOL )isLocal; - (void )setDropRow:(NSInteger )row dropOperation:(NSTableViewDropOperation )dropOperation; @property BOOL allowsMultipleSelection;@property BOOL allowsEmptySelection;@property BOOL allowsColumnSelection;- (void )selectAll:(nullable id )sender; - (void )deselectAll:(nullable id )sender; - (void )selectColumnIndexes:(NSIndexSet *)indexes byExtendingSelection:(BOOL )extend; - (void )selectRowIndexes:(NSIndexSet *)indexes byExtendingSelection:(BOOL )extend; @property (readonly , copy ) NSIndexSet *selectedColumnIndexes;@property (readonly , copy ) NSIndexSet *selectedRowIndexes;- (void )deselectColumn:(NSInteger )column; - (void )deselectRow:(NSInteger )row; - (BOOL )isColumnSelected:(NSInteger )column; - (BOOL )isRowSelected:(NSInteger )row; @property (readonly ) NSInteger numberOfSelectedColumns;@property (readonly ) NSInteger numberOfSelectedRows;- (NSRect )rectOfColumn:(NSInteger )column; - (NSRect )rectOfRow:(NSInteger )row; - (NSIndexSet *)columnIndexesInRect:(NSRect )rect; - (NSRange )rowsInRect:(NSRect )rect; - (NSInteger )columnAtPoint:(NSPoint )point; - (NSInteger )rowAtPoint:(NSPoint )point; - (NSRect )frameOfCellAtColumn:(NSInteger )column row:(NSInteger )row; - (nullable __kindof NSView *)viewAtColumn:(NSInteger )column row:(NSInteger )row makeIfNecessary:(BOOL )makeIfNecessary; - (nullable __kindof NSTableRowView *)rowViewAtRow:(NSInteger )row makeIfNecessary:(BOOL )makeIfNecessary; - (NSInteger )rowForView:(NSView *)view; - (NSInteger )columnForView:(NSView *)view; - (nullable __kindof NSView *)makeViewWithIdentifier:(NSString *)identifier owner:(nullable id )owner; - (void )beginUpdates NS_AVAILABLE_MAC (10 _7); - (void )endUpdates NS_AVAILABLE_MAC (10 _7); - (void )insertRowsAtIndexes:(NSIndexSet *)indexes withAnimation:(NSTableViewAnimationOptions )animationOptions NS_AVAILABLE_MAC (10 _7); - (void )removeRowsAtIndexes:(NSIndexSet *)indexes withAnimation:(NSTableViewAnimationOptions )animationOptions NS_AVAILABLE_MAC (10 _7); - (void )moveRowAtIndex:(NSInteger )oldIndex toIndex:(NSInteger )newIndex NS_AVAILABLE_MAC (10 _7); - (void )hideRowsAtIndexes:(NSIndexSet *)indexes withAnimation:(NSTableViewAnimationOptions )rowAnimation NS_AVAILABLE_MAC (10 _11); - (void )unhideRowsAtIndexes:(NSIndexSet *)indexes withAnimation:(NSTableViewAnimationOptions )rowAnimation NS_AVAILABLE_MAC (10 _11); @property (readonly , copy ) NSIndexSet *hiddenRowIndexes;
十、相关通知 1 2 3 4 5 6 7 8 APPKIT_EXTERN NSNotificationName NSTableViewSelectionDidChangeNotification ; APPKIT_EXTERN NSNotificationName NSTableViewColumnDidMoveNotification ; APPKIT_EXTERN NSNotificationName NSTableViewColumnDidResizeNotification ; APPKIT_EXTERN NSNotificationName NSTableViewSelectionIsChangingNotification ;