PictureSearchViewController.mm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // PictureSearchViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/16.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "PictureSearchViewController.h"
  9. #import "PictureFileConfig.h"
  10. #import "PictureDownloadViewController.h"
  11. #import "ItemTableviewCell.h"
  12. #import "Header.h"
  13. @interface PictureSearchViewController () <UITableViewDelegate, UITableViewDataSource, PictureFileConfigDelegate>
  14. {
  15. PictureFileConfig *config;
  16. UITableView *tableV;
  17. NSMutableArray *pictureArray;
  18. }
  19. @end
  20. @implementation PictureSearchViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. //初始化tableview数据
  24. [self initDataSource];
  25. [self configSubView];
  26. [self getVideoFileConfig];
  27. }
  28. - (void)viewWillDisappear:(BOOL)animated{
  29. //有加载状态、则取消加载
  30. if ([SVProgressHUD isVisible]){
  31. [SVProgressHUD dismiss];
  32. }
  33. }
  34. #pragma mark - 按文件查询设备图片信息
  35. - (void)getVideoFileConfig {
  36. [SVProgressHUD showWithStatus:TS("")];
  37. if (config == nil) {
  38. config = [[PictureFileConfig alloc] init];
  39. config.delegate = self;
  40. }
  41. //调用按文件查询图片的接口,查询今天的设备图片,可以设置其他想要查询的日期
  42. [config getDevicePictureByFile:[NSDate date]];
  43. }
  44. #pragma mark 获取摄像机图片代理回调
  45. - (void)getPictureResult:(NSInteger)result {
  46. if (result >= 0) {
  47. [SVProgressHUD dismiss];
  48. pictureArray = [config getPictureFileArray];
  49. //成功,刷新界面数据
  50. [self.tableV reloadData];
  51. }else{
  52. [MessageUI ShowErrorInt:(int)result];
  53. }
  54. }
  55. #pragma mark - tableView代理方法
  56. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  57. return pictureArray.count;
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  61. if (!cell) {
  62. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  63. }
  64. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  65. PictureInfo *pic = [pictureArray objectAtIndex:indexPath.row];
  66. cell.textLabel.text = pic.fileName;
  67. cell.textLabel.numberOfLines = 0;
  68. cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  69. return cell;
  70. }
  71. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  72. //点击下载图片
  73. PictureDownloadViewController *downloadVC = [[PictureDownloadViewController alloc] init];
  74. [self.navigationController pushViewController:downloadVC animated:YES];
  75. PictureInfo *picInfo = [pictureArray objectAtIndex:indexPath.row];
  76. [downloadVC startDownloadPicture:picInfo];
  77. }
  78. #pragma mark - 界面和数据初始化
  79. - (void)configSubView {
  80. self.title = TS("search_picture");
  81. [self.view addSubview:self.tableV];
  82. }
  83. - (UITableView *)tableV {
  84. if (!tableV) {
  85. tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  86. tableV.delegate = self;
  87. tableV.dataSource = self;
  88. [tableV registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  89. }
  90. return tableV;
  91. }
  92. #pragma mark - 界面和数据初始化
  93. - (void)initDataSource {
  94. pictureArray = [[NSMutableArray alloc] initWithCapacity:0];
  95. }
  96. - (void)didReceiveMemoryWarning {
  97. [super didReceiveMemoryWarning];
  98. // Dispose of any resources that can be recreated.
  99. }
  100. @end