ApexDriverUploadListVC.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. }
  26. - (void)didReceiveMemoryWarning {
  27. [super didReceiveMemoryWarning];
  28. // Dispose of any resources that can be recreated.
  29. }
  30. - (UITableView *)uploadTableView {
  31. return self.tableView;
  32. }
  33. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  34. ApexDriverUploadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ApexDriverUploadCell" forIndexPath:indexPath];
  35. AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  36. NSDictionary * item_json = appdelegate.uploadManager.arr_queue[indexPath.row];
  37. RAUploadOperation* op = item_json[@"operation"];
  38. NSString* status =nil;
  39. switch ([item_json[@"status"] intValue]) {
  40. case TaskStatusStart:
  41. status=@"uploading";
  42. break;
  43. case TaskStatusStop:
  44. status=@"stop";
  45. break;
  46. case TaskStatusError:
  47. status=@"warning";
  48. break;
  49. case TaskStatusWait:
  50. status=@"waiting";
  51. break;
  52. case TaskStatusFinish:
  53. status=@"finish";
  54. break;
  55. default:
  56. status=@"warning";
  57. break;
  58. }
  59. double progress =[item_json[@"progress"] doubleValue];
  60. cell.progress = progress;
  61. cell.orderID = item_json[@"order"];
  62. cell.action = item_json[@"action"];
  63. cell.status = status;
  64. cell.errMsg = item_json[@"msg"];
  65. op.updateUI=^(){
  66. NSString* status =nil;
  67. switch ([item_json[@"status"] intValue]) {
  68. case TaskStatusStart:
  69. status=@"uploading";
  70. break;
  71. case TaskStatusStop:
  72. status=@"stop";
  73. break;
  74. case TaskStatusError:
  75. status=@"warning";
  76. break;
  77. case TaskStatusWait:
  78. status=@"waiting";
  79. break;
  80. case TaskStatusFinish:
  81. status=@"finish";
  82. break;
  83. default:
  84. status=@"warning";
  85. break;
  86. }
  87. double progress =[item_json[@"progress"] doubleValue];
  88. cell.progress = progress;
  89. cell.orderID = item_json[@"order"];
  90. cell.action = item_json[@"action"];
  91. cell.status = status;
  92. cell.errMsg = item_json[@"msg"];
  93. };
  94. return cell;
  95. }
  96. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  97. ApexDriverUploadCell *upCell = (ApexDriverUploadCell *)cell;
  98. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  99. NSUInteger row = indexPath.row;
  100. NSUInteger count = Appdelegate.uploadManager.arr_queue.count;
  101. if (count > row) {
  102. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  103. RAUploadOperation* operation = item_json[@"operation"];
  104. ApexDriverUploadCell *newCell = (ApexDriverUploadCell *)[tableView cellForRowAtIndexPath:indexPath];
  105. if (newCell != upCell) {
  106. // reload row
  107. } else {
  108. operation.updateUI = nil; // restart 会调用就会导致cell不会刷新
  109. }
  110. }
  111. [upCell reset];
  112. }
  113. @end