MyTable.m
资源名称:PushBox.rar [点击查看]
上传用户:qhdwjd2004
上传日期:2020-12-29
资源大小:362k
文件大小:5k
源码类别:
iPhone
开发平台:
Objective-C
- #import "MyTable.h"
- #import "ListView.h"
- #import <dirent.h>
- @implementation MyTable
- -(id)initWithFrame : (struct CGRect)rect
- {
- if((self == [super initWithFrame: rect]) != nil){
- colFilename = [ [ UITableColumn alloc ]
- initWithTitle: @"Filename"
- identifier:@"filename"
- width: rect.size.width
- ];
- [self addTableColumn: colFilename];
- [self setSeparatorStyle:1];
- [self setDelegate: self];
- [self setDataSource: self];
- [self setRowHeight: 64 ];
- fileList = [[NSMutableArray alloc] init];
- }
- return self;
- }
- -(void)dealloc
- {
- [ colFilename release ];
- [ colType release ];
- [ fileList release ];
- [super dealloc];
- }
- -(int)numberOfRowsInTable:(UITable *)_table
- {
- if(state==0)
- {
- NSLog(@"%i",maxChapterNum);
- return maxChapterNum;
- }
- else
- {
- NSLog(@"%i",[ fileList count ]);
- return [ fileList count ];
- }
- }
- -(UITableCell *)table:(UITable *)table
- cellForRow:(int)row
- column:(UITableColumn *)col
- {
- DeletableCell *cell = [ [ DeletableCell alloc ] init ];
- [ cell setTable: self ];
- NSLog(@"row");
- if(state==0)
- {
- [ cell setTitle: [[[ NSString alloc ] initWithFormat: @"Stage %i/", row+1 ]
- stringByDeletingPathExtension ]];
- [ cell setImage: [UIImage applicationImageNamed:@"images/chapter.png"] ];
- NSLog(@"%i",row);
- }
- else
- {
- [ cell setTitle: [ [ fileList objectAtIndex: row ]
- stringByDeletingPathExtension ]];
- [ cell setImage: [UIImage applicationImageNamed:@"images/map.png"] ];
- }
- [ cell setShowDisclosure: YES ];
- [ cell setDisclosureStyle: 3 ];
- return [ cell autorelease ];
- }
- -(int)swipe:(int)type withEvent:(struct __GSEvent *)event
- {
- if(state != 0) // 只有自定义地图才能被删除
- {
- CGPoint point= GSEventGetLocationInWindow(event);
- CGPoint offset = _startOffset;
- if (point.x < 100 || point.x > 200) {
- point.x += offset.x;
- point.y += offset.y-48;
- int row = [ self rowAtPoint:point ];
- [ [ self visibleCellForRow: row column: 0 ]
- _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
- {
- int index = [ self selectedRow ];
- if(selectIndex!=index)
- {
- selectIndex = index;
- }
- else
- {
- selectIndex = -1;
- if(state ==0)
- {
- [(ListView *)listView itemSelected: (id)index];
- }
- else
- {
- [(ListView *)listView itemSelected: (id)[ fileList objectAtIndex: index ]];
- }
- }
- }
- -(int)getState
- {
- return state;
- }
- -(void)setState:(int)st
- {
- state = st;
- }
- -(void)setMaxChapter:(int)chapter
- {
- if(chapter>0)
- maxChapterNum = chapter;
- else
- maxChapterNum = 1;
- }
- -(void)setPath:(NSString *)_path
- {
- path = [ _path copy];
- }
- -(void)setView:(UIView *)_mainView
- {
- listView = _mainView;
- }
- -(void)reloadData
- {
- if(state ==0)
- {
- }
- else
- {
- // 重置
- [ fileList removeAllObjects ];
- NSFileManager *fileManager = [ NSFileManager defaultManager ];
- NSDirectoryEnumerator *dirEnum;
- NSString *file;
- BOOL isdir;
- // 判断目录是否存在
- if ([ fileManager fileExistsAtPath: path isDirectory:&isdir] == YES
- && isdir)
- {
- // 加载数据
- NSArray *flist = [[NSFileManager defaultManager] directoryContentsAtPath: path];
- int i=0;
- NSEnumerator *enumerator = [flist objectEnumerator];
- id obj;
- while (obj = [enumerator nextObject]) {
- file = (NSString*)obj;
- if([file hasSuffix: [[NSString alloc] initWithCString: MAP_FILE_SUFFIX ]] == YES)
- {
- [ fileList addObject: file ];
- }
- }
- }
- }
- selectIndex = -1;
- [ super reloadData ];
- }
- // 删除数据
- -(void)itemDelete:(int)index
- {
- NSString *dfilepath = [[[[NSString alloc] initWithCString:Custom_Map_Path] stringByExpandingTildeInPath]
- stringByAppendingPathComponent:(NSString*)[ fileList objectAtIndex: index ]];
- [(ListView*)listView deleteMap:dfilepath];
- }
- @end
- @implementation DeletableCell
- - (void)removeControlWillHideRemoveConfirmation:(id)fp8
- {
- [ self _showDeleteOrInsertion:NO
- withDisclosure:NO
- animated:YES
- isDelete:YES
- andRemoveConfirmation:YES
- ];
- }
- - (void)_willBeDeleted
- {
- int row = [ table _rowForTableCell: self ];
- [table itemDelete:row];
- /* Do something; this row is being deleted */
- }
- - (void)setTable:(MyTable *)_table {
- table = _table;
- }
- @end