FavoritesViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // FavoritesViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-4-25.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "FavoritesViewController.h"
  9. @interface FavoritesViewController ()
  10. @end
  11. @implementation FavoritesViewController
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  13. {
  14. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  15. if (self) {
  16. // Custom initialization
  17. }
  18. return self;
  19. }
  20. - (BOOL)shouldAutorotate
  21. {
  22. return YES;
  23. }
  24. - (NSUInteger)supportedInterfaceOrientations
  25. {
  26. return UIInterfaceOrientationMaskPortrait;
  27. }
  28. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  29. {
  30. return UIInterfaceOrientationPortrait;
  31. }
  32. - (void)viewDidLoad
  33. {
  34. [super viewDidLoad];
  35. self.data =[[FavoritesData alloc]init];
  36. [self.tableview reloadData];
  37. self.tableview.tableFooterView = [UIView new];
  38. }
  39. -(void)viewWillAppear:(BOOL)animated
  40. {
  41. }
  42. - (void)didReceiveMemoryWarning
  43. {
  44. [super didReceiveMemoryWarning];
  45. // Dispose of any resources that can be recreated.
  46. }
  47. /*
  48. #pragma mark - Navigation
  49. // In a storyboard-based application, you will often want to do a little preparation before navigation
  50. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  51. {
  52. // Get the new view controller using [segue destinationViewController].
  53. // Pass the selected object to the new view controller.
  54. }
  55. */
  56. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  57. {
  58. return 1;
  59. }
  60. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  61. {
  62. return [self.data get_count];
  63. }
  64. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. DebugLog(@"cellForRowAtIndexPath");
  67. NSString *CellIdentifier = @"cell_item_history";
  68. CellItemHistory *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  69. NSString* name = [self.data.pagedata[indexPath.row] valueForKey:@"name"];
  70. NSString* create_time = [self.data.pagedata[indexPath.row] valueForKey:@"create_time"];
  71. NSString *module_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
  72. // Cargo Tracking
  73. if ([module_name isEqualToString:@"Ocean Booking"]) {
  74. cell.icon.image = [[UIImage imageNamed:@"mode_booking"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  75. } else if ([module_name isEqualToString:@"Container detail"]) {
  76. cell.icon.image = [[UIImage imageNamed:@"mode_container"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  77. } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
  78. cell.icon.image = [[UIImage imageNamed:@"mode_bl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  79. } else if ([module_name isEqualToString:@"Cargo Tracking"]) {
  80. cell.icon.image = [[UIImage imageNamed:@"mode_cargo_tracking"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  81. } else {
  82. cell.icon.image = [[UIImage imageNamed:@"mode_document"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  83. }
  84. cell.name.text = name;
  85. [cell.name sizeToFit];
  86. cell.time.text =create_time;
  87. [cell.time sizeToFit];
  88. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  89. return cell;
  90. }
  91. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  92. {
  93. // NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
  94. NSString* str_params =[self.data.pagedata[indexPath.row] valueForKey:@"params"];
  95. NSData* data_params = [str_params dataUsingEncoding:NSUTF8StringEncoding];
  96. NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithDictionary:[NSJSONSerialization
  97. JSONObjectWithData:data_params
  98. options:NSJSONReadingMutableLeaves
  99. error:nil] copyItems:true];
  100. NSString * str_actions =[self.data.pagedata[indexPath.row] valueForKey:@"action"];
  101. NSArray* actions = [str_actions componentsSeparatedByString:@","];
  102. NSString* function_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
  103. DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:function_name actions:actions params:params];
  104. // DetailTabBarController *detailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailTabBarController"];
  105. // detailViewController.function_name = self.function_name;
  106. // detailViewController.actions = self.actions;
  107. // detailViewController.params =params;
  108. [self.navigationController pushViewController:detailViewController animated:YES];
  109. }
  110. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  111. return UITableViewCellEditingStyleDelete;
  112. //不能是UITableViewCellEditingStyleNone
  113. }
  114. - (void)tableView:(UITableView *)tableView
  115. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  116. sqlite3* db = [ApexMobileDB get_db];
  117. NSString* sql = [NSString stringWithFormat:@"delete from favorites where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  118. [ApexMobileDB execSql:sql db:db];
  119. sqlite3_close(db);
  120. [self.data.pagedata removeObjectAtIndex:indexPath.row];
  121. [tableView reloadData];
  122. }
  123. @end