ListView.m
上传用户:qhdwjd2004
上传日期:2020-12-29
资源大小:362k
文件大小:4k
源码类别:

iPhone

开发平台:

Objective-C

  1. #import "ListView.h"
  2. #import "MainView.h"
  3. @implementation ListView
  4. //////////////////////////////////////////////////////
  5. // 视图函数
  6. //////////////////////////////////////////////////////
  7. - (id)initWithFrame:(CGRect)rect
  8. {
  9.     if((self == [super initWithFrame:rect])!=nil)
  10.     {
  11.         CGRect rect = [ UIHardware fullScreenApplicationContentRect ];
  12.         rect.origin.x = 0;
  13.         rect.origin.y = 0;
  14.         navBar = [ [UINavigationBar alloc] initWithFrame: CGRectMake(0, 0, 320, 48)];
  15. [ navBar setDelegate: self ];
  16. [ navBar enableAnimation ];
  17. [ navBar setBarStyle: 0 ];
  18.         navTitle = [ [ UINavigationItem alloc ] initWithTitle:@"/" ];
  19.         [ navBar pushNavigationItem: navTitle ];
  20. [ self addSubview: navBar ];
  21.         mapListTable = [ [ MyTable alloc ] initWithFrame: CGRectMake(0, 48, 320, rect.size.height - 48)];
  22.         [ mapListTable setView: self];
  23.         [ self addSubview: mapListTable ];
  24.         [ mapListTable setState: 0];
  25.         [ mapListTable setMaxChapter: 1];
  26.         [ mapListTable reloadData ];
  27.         [self setNavBar: 0 withTitle:@"Stages"];
  28.     }
  29.     return self;
  30. }
  31. // 释放资源
  32. - (void)dealloc
  33. {
  34.     [mapListTable release];
  35.     [navTitle release];
  36.     [navBar release];
  37.     [self dealloc];
  38.     [super dealloc];
  39. }
  40. // 设置导航栏
  41. -(void)setNavBar:(int)state withTitle:(NSString*)title
  42. {
  43.     if(state ==0)
  44.     {
  45.         [ navBar showLeftButton:@"Back" withStyle: 0 rightButton:@"Maps" withStyle: 0 ];
  46.     }
  47.     else
  48.     {
  49.         [ navBar showLeftButton:@"Back" withStyle: 0 rightButton:nil withStyle: 0 ];
  50.     }
  51.     current = state;
  52.     [ navTitle setTitle: title ];
  53. }
  54. // 导航栏
  55. - (void)navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button
  56. {
  57. switch(button)
  58. {
  59.     case 1:
  60.         if(current == 0)
  61.         {
  62.             [(MainView*)parentView showCover];
  63.         }
  64.         else
  65.         {
  66.             [self loadChapterList];
  67.         }
  68. break;
  69.     case 0:
  70.         [self loadMapList];
  71.         break;
  72. }
  73. }
  74. //////////////////////////////////////////////////////
  75. // 加载/保存
  76. //////////////////////////////////////////////////////
  77. -(void)loadChapterList
  78. {
  79.     if([Map CheckMessExist])
  80.     {
  81.         Mess mdata = [Map LoadMess];
  82.         [mapListTable setMaxChapter: mdata.enableChapterCount];
  83.     }
  84.     else
  85.     {
  86.         [ mapListTable setMaxChapter: 1];
  87.     }
  88.     [ mapListTable setState: 0];
  89.     [ mapListTable reloadData ];
  90.     [self setNavBar: 0 withTitle:@"Stages"];
  91. }
  92. -(void)loadMapList
  93. {
  94.     NSString *mPath = [[[NSString alloc] initWithCString: Custom_Map_Path] stringByExpandingTildeInPath];
  95.     if(![Map DirExist:mPath])
  96.     {
  97.         [Map CreateDir:mPath];
  98.     }
  99.     [ mapListTable setState: 1];
  100.     [ mapListTable setPath: mPath];
  101.     [ mapListTable reloadData ];
  102.     [self setNavBar: 1 withTitle: @"Maps"];
  103. }
  104. //////////////////////////////////////////////////////
  105. // 设置
  106. //////////////////////////////////////////////////////
  107. // 设置主视图
  108. - (void)setParentView:(UIView*)view
  109. {
  110.     parentView = view;
  111. }
  112. // 选择项
  113. -(void)itemSelected:(id)value
  114. {
  115.     if(current == 0)
  116.     {
  117.         NSLog(@"%i",(int)value);
  118.         [(MainView*)parentView characterSelected:(int)value];
  119.     }
  120.     else
  121.     {
  122.          NSLog(@"%@",(NSString*)value);
  123.          NSString *path = [[[[NSString alloc] initWithCString:Custom_Map_Path] stringByExpandingTildeInPath] stringByAppendingPathComponent:(NSString*)value];
  124.          [(MainView*)parentView mapSelected:path];
  125.     }
  126. }
  127. // 删除自定义地图
  128. -(void)deleteMap:(NSString*)mapfile
  129. {
  130.     [Map DeleteMap:mapfile];
  131. }
  132. @end