ListView.m
资源名称:PushBox.rar [点击查看]
上传用户:qhdwjd2004
上传日期:2020-12-29
资源大小:362k
文件大小:4k
源码类别:
iPhone
开发平台:
Objective-C
- #import "ListView.h"
- #import "MainView.h"
- @implementation ListView
- //////////////////////////////////////////////////////
- // 视图函数
- //////////////////////////////////////////////////////
- - (id)initWithFrame:(CGRect)rect
- {
- if((self == [super initWithFrame:rect])!=nil)
- {
- CGRect rect = [ UIHardware fullScreenApplicationContentRect ];
- rect.origin.x = 0;
- rect.origin.y = 0;
- navBar = [ [UINavigationBar alloc] initWithFrame: CGRectMake(0, 0, 320, 48)];
- [ navBar setDelegate: self ];
- [ navBar enableAnimation ];
- [ navBar setBarStyle: 0 ];
- navTitle = [ [ UINavigationItem alloc ] initWithTitle:@"/" ];
- [ navBar pushNavigationItem: navTitle ];
- [ self addSubview: navBar ];
- mapListTable = [ [ MyTable alloc ] initWithFrame: CGRectMake(0, 48, 320, rect.size.height - 48)];
- [ mapListTable setView: self];
- [ self addSubview: mapListTable ];
- [ mapListTable setState: 0];
- [ mapListTable setMaxChapter: 1];
- [ mapListTable reloadData ];
- [self setNavBar: 0 withTitle:@"Stages"];
- }
- return self;
- }
- // 释放资源
- - (void)dealloc
- {
- [mapListTable release];
- [navTitle release];
- [navBar release];
- [self dealloc];
- [super dealloc];
- }
- // 设置导航栏
- -(void)setNavBar:(int)state withTitle:(NSString*)title
- {
- if(state ==0)
- {
- [ navBar showLeftButton:@"Back" withStyle: 0 rightButton:@"Maps" withStyle: 0 ];
- }
- else
- {
- [ navBar showLeftButton:@"Back" withStyle: 0 rightButton:nil withStyle: 0 ];
- }
- current = state;
- [ navTitle setTitle: title ];
- }
- // 导航栏
- - (void)navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button
- {
- switch(button)
- {
- case 1:
- if(current == 0)
- {
- [(MainView*)parentView showCover];
- }
- else
- {
- [self loadChapterList];
- }
- break;
- case 0:
- [self loadMapList];
- break;
- }
- }
- //////////////////////////////////////////////////////
- // 加载/保存
- //////////////////////////////////////////////////////
- -(void)loadChapterList
- {
- if([Map CheckMessExist])
- {
- Mess mdata = [Map LoadMess];
- [mapListTable setMaxChapter: mdata.enableChapterCount];
- }
- else
- {
- [ mapListTable setMaxChapter: 1];
- }
- [ mapListTable setState: 0];
- [ mapListTable reloadData ];
- [self setNavBar: 0 withTitle:@"Stages"];
- }
- -(void)loadMapList
- {
- NSString *mPath = [[[NSString alloc] initWithCString: Custom_Map_Path] stringByExpandingTildeInPath];
- if(![Map DirExist:mPath])
- {
- [Map CreateDir:mPath];
- }
- [ mapListTable setState: 1];
- [ mapListTable setPath: mPath];
- [ mapListTable reloadData ];
- [self setNavBar: 1 withTitle: @"Maps"];
- }
- //////////////////////////////////////////////////////
- // 设置
- //////////////////////////////////////////////////////
- // 设置主视图
- - (void)setParentView:(UIView*)view
- {
- parentView = view;
- }
- // 选择项
- -(void)itemSelected:(id)value
- {
- if(current == 0)
- {
- NSLog(@"%i",(int)value);
- [(MainView*)parentView characterSelected:(int)value];
- }
- else
- {
- NSLog(@"%@",(NSString*)value);
- NSString *path = [[[[NSString alloc] initWithCString:Custom_Map_Path] stringByExpandingTildeInPath] stringByAppendingPathComponent:(NSString*)value];
- [(MainView*)parentView mapSelected:path];
- }
- }
- // 删除自定义地图
- -(void)deleteMap:(NSString*)mapfile
- {
- [Map DeleteMap:mapfile];
- }
- @end