📄 filetable.m
字号:
#import "FileTable.h"#import "UIDeletableCell.h"@implementation FileTable- (id)initWithFrame:(struct CGRect)rect { self = [ super initWithFrame: rect ]; if (nil != self) { colFilename = [ [ UITableColumn alloc ] initWithTitle: @"Filename" identifier:@"filename" width: rect.size.width - 75 ]; [ self addTableColumn: colFilename ]; colType = [ [ UITableColumn alloc ] initWithTitle: @"Type" identifier:@"type" width: 75 ]; [ self addTableColumn: colType ]; [ self setSeparatorStyle: 1 ]; [ self setDelegate: self ]; [ self setDataSource: self ]; [ self setRowHeight: 64 ]; fileList = [ [ NSMutableArray alloc] init ]; } return self;}- (void) setPath:(NSString *)_path { path = [ _path copy ];}- (void) setExtension:(NSString *)_extension { extension = [ _extension copy ];}- (void) reloadData { NSFileManager *fileManager = [ NSFileManager defaultManager ]; NSDirectoryEnumerator *dirEnum; NSString *file; if ([ fileManager fileExistsAtPath: path ] == NO) { return; } [ fileList removeAllObjects ]; dirEnum = [ [ NSFileManager defaultManager ] enumeratorAtPath: path ]; while ((file = [ dirEnum nextObject ])) { if ([ file hasSuffix: extension ] == YES) { [ fileList addObject: file ]; } } [ super reloadData ];}- (int)numberOfRowsInTable:(UITable *)_table { return [ fileList count ];}- (UITableCell *)table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col{ if (col == colFilename) { UIDeletableCell *cell = [ [ UIDeletableCell alloc ] init ]; [ cell setTable: self ]; UIImageView *image = [ [ UIImage alloc ] initWithContentsOfFile: [ [ NSString alloc ] initWithFormat: @"/Applications/%@/icon.png", [ fileList objectAtIndex: row ] ] ]; [ cell setTitle: [ [ fileList objectAtIndex: row ] stringByDeletingPathExtension ]]; [ cell setImage: image ];[ cell setShowDisclosure: YES ];[ cell setDisclosureStyle: 3 ]; return [ cell autorelease ]; } else if (col == colType) { UIDeletableCell *cell = [ [ UIDeletableCell alloc ] init ]; [ cell setTable: self ]; [ cell setTitle: extension ]; return [ cell autorelease ]; }}- (int)swipe:(int)type withEvent:(struct __GSEvent *)event;{ CGPoint point= GSEventGetLocationInWindow(event); CGPoint offset = _startOffset; if (point.x < 100 || point.x > 200) { point.x += offset.x; point.y += offset.y; int row = [ self rowAtPoint:point ]; [ [ self visibleCellForRow: row column: 1 ] _showDeleteOrInsertion: YES withDisclosure: NO animated: YES isDelete: YES andRemoveConfirmation: YES ]; return [ super swipe:type withEvent:event ]; }}- (void)_willDeleteRow:(int)row forTableCell:(id)cell viaEdge:(int)edge animateOthers:(BOOL)animate { [ fileList removeObjectAtIndex: row ]; [ super _willDeleteRow: row forTableCell: cell viaEdge: edge animateOthers: animate ];}- (void)tableRowSelected:(NSNotification *)notification { NSString *fileName = [ fileList objectAtIndex: [ self selectedRow ] ]; /* A file was selected. Do something here. */}- (void)dealloc { [ colFilename release ]; [ colType release ]; [ fileList release ]; [ super dealloc ];} @end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -