FavoritesViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. }
  38. -(void)viewWillAppear:(BOOL)animated
  39. {
  40. }
  41. - (void)didReceiveMemoryWarning
  42. {
  43. [super didReceiveMemoryWarning];
  44. // Dispose of any resources that can be recreated.
  45. }
  46. /*
  47. #pragma mark - Navigation
  48. // In a storyboard-based application, you will often want to do a little preparation before navigation
  49. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  50. {
  51. // Get the new view controller using [segue destinationViewController].
  52. // Pass the selected object to the new view controller.
  53. }
  54. */
  55. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  56. {
  57. return 1;
  58. }
  59. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  60. {
  61. return [self.data get_count];
  62. }
  63. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  64. {
  65. DebugLog(@"cellForRowAtIndexPath");
  66. NSString *CellIdentifier = @"cell_item_history";
  67. CellItemHistory *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  68. NSString* name = [self.data.pagedata[indexPath.row] valueForKey:@"name"];
  69. NSString* create_time = [self.data.pagedata[indexPath.row] valueForKey:@"create_time"];
  70. NSString *module_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
  71. // Cargo Tracking
  72. if ([module_name isEqualToString:@"Ocean Booking"]) {
  73. cell.icon.image = [[UIImage imageNamed:@"mode_booking"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  74. } else if ([module_name isEqualToString:@"Container detail"]) {
  75. cell.icon.image = [[UIImage imageNamed:@"mode_container"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  76. } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
  77. cell.icon.image = [[UIImage imageNamed:@"mode_bl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  78. } else if ([module_name isEqualToString:@"Cargo Tracking"]) {
  79. cell.icon.image = [[UIImage imageNamed:@"mode_cargo_tracking"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  80. } else {
  81. cell.icon.image = [[UIImage imageNamed:@"mode_document"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  82. }
  83. cell.name.text = name;
  84. [cell.name sizeToFit];
  85. cell.time.text =create_time;
  86. [cell.time sizeToFit];
  87. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  88. return cell;
  89. }
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  91. {
  92. // NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
  93. NSString* str_params =[self.data.pagedata[indexPath.row] valueForKey:@"params"];
  94. NSData* data_params = [str_params dataUsingEncoding:NSUTF8StringEncoding];
  95. NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithDictionary:[NSJSONSerialization
  96. JSONObjectWithData:data_params
  97. options:NSJSONReadingMutableLeaves
  98. error:nil] copyItems:true];
  99. NSString * str_actions =[self.data.pagedata[indexPath.row] valueForKey:@"action"];
  100. NSArray* actions = [str_actions componentsSeparatedByString:@","];
  101. NSString* function_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
  102. DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:function_name actions:actions params:params];
  103. // DetailTabBarController *detailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailTabBarController"];
  104. // detailViewController.function_name = self.function_name;
  105. // detailViewController.actions = self.actions;
  106. // detailViewController.params =params;
  107. [self.navigationController pushViewController:detailViewController animated:YES];
  108. }
  109. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  110. return UITableViewCellEditingStyleDelete;
  111. //不能是UITableViewCellEditingStyleNone
  112. }
  113. - (void)tableView:(UITableView *)tableView
  114. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  115. sqlite3* db = [ApexMobileDB get_db];
  116. NSString* sql = [NSString stringWithFormat:@"delete from favorites where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  117. [ApexMobileDB execSql:sql db:db];
  118. sqlite3_close(db);
  119. [self.data.pagedata removeObjectAtIndex:indexPath.row];
  120. [tableView reloadData];
  121. }
  122. @end