FavoritesViewController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. cell.name.text = name;
  71. [cell.name sizeToFit];
  72. cell.time.text =create_time;
  73. [cell.time sizeToFit];
  74. // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
  75. return cell;
  76. }
  77. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. // NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
  80. NSString* str_params =[self.data.pagedata[indexPath.row] valueForKey:@"params"];
  81. NSData* data_params = [str_params dataUsingEncoding:NSUTF8StringEncoding];
  82. NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithDictionary:[NSJSONSerialization
  83. JSONObjectWithData:data_params
  84. options:NSJSONReadingMutableLeaves
  85. error:nil] copyItems:true];
  86. NSString * str_actions =[self.data.pagedata[indexPath.row] valueForKey:@"action"];
  87. NSArray* actions = [str_actions componentsSeparatedByString:@","];
  88. NSString* function_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
  89. DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:function_name actions:actions params:params];
  90. // DetailTabBarController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailTabBarController"];
  91. // detailViewController.function_name = self.function_name;
  92. // detailViewController.actions = self.actions;
  93. // detailViewController.params =params;
  94. [self.navigationController pushViewController:detailViewController animated:YES];
  95. }
  96. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  97. return UITableViewCellEditingStyleDelete;
  98. //不能是UITableViewCellEditingStyleNone
  99. }
  100. - (void)tableView:(UITableView *)tableView
  101. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  102. sqlite3* db = [ApexMobileDB get_db];
  103. NSString* sql = [NSString stringWithFormat:@"delete from favorites where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  104. [ApexMobileDB execSql:sql db:db];
  105. sqlite3_close(db);
  106. [self.data.pagedata removeObjectAtIndex:indexPath.row];
  107. [tableView reloadData];
  108. }
  109. @end