ApexDriverUploadListVC.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // ApexDriverUploadListVC.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/6.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "ApexDriverUploadListVC.h"
  9. #import "ApexDriverUploadCell.h"
  10. #import "AppDelegate.h"
  11. @interface ApexDriverUploadListVC ()
  12. @property (strong, nonatomic) IBOutlet UITableView *tableView;
  13. @end
  14. @implementation ApexDriverUploadListVC
  15. + (NSString *)storyboardID {
  16. return NSStringFromClass([self class]);
  17. }
  18. + (instancetype)viewControllerFromStoryboard {
  19. ApexDriverUploadListVC *uploadVC = [[UIStoryboard storyboardWithName:@"Upload" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  20. return uploadVC;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. // Dispose of any resources that can be recreated.
  30. }
  31. - (UITableView *)uploadTableView {
  32. return self.tableView;
  33. }
  34. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  35. ApexDriverUploadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ApexDriverUploadCell" forIndexPath:indexPath];
  36. AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  37. NSDictionary * item_json = appdelegate.uploadManager.arr_queue[indexPath.row];
  38. RAUploadOperation* op = item_json[@"operation"];
  39. NSString* status =nil;
  40. switch ([item_json[@"status"] intValue]) {
  41. case TaskStatusStart:
  42. status=@"uploading";
  43. break;
  44. case TaskStatusStop:
  45. status=@"stop";
  46. break;
  47. case TaskStatusError:
  48. status=@"warning";
  49. break;
  50. case TaskStatusWait:
  51. status=@"waiting";
  52. break;
  53. case TaskStatusFinish:
  54. status=@"finish";
  55. break;
  56. default:
  57. status=@"warning";
  58. break;
  59. }
  60. double progress =[item_json[@"progress"] doubleValue];
  61. cell.progress = progress;
  62. cell.orderID = item_json[@"order"];
  63. cell.action = item_json[@"action"];
  64. cell.status = status;
  65. cell.errMsg = item_json[@"msg"];
  66. cell.datetime = item_json[@"time"];
  67. cell.photoName = item_json[@"name"];
  68. op.updateUI=^(){
  69. NSString* status =nil;
  70. switch ([item_json[@"status"] intValue]) {
  71. case TaskStatusStart:
  72. status=@"uploading";
  73. break;
  74. case TaskStatusStop:
  75. status=@"stop";
  76. break;
  77. case TaskStatusError:
  78. status=@"warning";
  79. break;
  80. case TaskStatusWait:
  81. status=@"waiting";
  82. break;
  83. case TaskStatusFinish:
  84. status=@"finish";
  85. break;
  86. default:
  87. status=@"warning";
  88. break;
  89. }
  90. double progress =[item_json[@"progress"] doubleValue];
  91. cell.progress = progress;
  92. cell.orderID = item_json[@"order"];
  93. cell.action = item_json[@"action"];
  94. cell.status = status;
  95. cell.errMsg = item_json[@"msg"];
  96. cell.datetime = item_json[@"time"];
  97. cell.photoName = item_json[@"name"];
  98. };
  99. return cell;
  100. }
  101. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  102. ApexDriverUploadCell *upCell = (ApexDriverUploadCell *)cell;
  103. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  104. NSUInteger row = indexPath.row;
  105. NSUInteger count = Appdelegate.uploadManager.arr_queue.count;
  106. if (count > row) {
  107. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  108. RAUploadOperation* operation = item_json[@"operation"];
  109. ApexDriverUploadCell *newCell = (ApexDriverUploadCell *)[tableView cellForRowAtIndexPath:indexPath];
  110. if (newCell != upCell) {
  111. // reload row
  112. } else {
  113. operation.updateUI = nil; // restart 会调用就会导致cell不会刷新
  114. }
  115. }
  116. [upCell reset];
  117. }
  118. @end