// // ApexDriverUploadListVC.m // Apex And Drivers // // Created by Jack on 2018/6/6. // Copyright © 2018年 USAI. All rights reserved. // #import "ApexDriverUploadListVC.h" #import "ApexDriverUploadCell.h" #import "AppDelegate.h" @interface ApexDriverUploadListVC () @property (strong, nonatomic) IBOutlet UITableView *tableView; @end @implementation ApexDriverUploadListVC + (NSString *)storyboardID { return NSStringFromClass([self class]); } + (instancetype)viewControllerFromStoryboard { ApexDriverUploadListVC *uploadVC = [[UIStoryboard storyboardWithName:@"Upload" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]]; return uploadVC; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (UITableView *)uploadTableView { return self.tableView; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ApexDriverUploadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ApexDriverUploadCell" forIndexPath:indexPath]; AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate; NSDictionary * item_json = appdelegate.uploadManager.arr_queue[indexPath.row]; RAUploadOperation* op = item_json[@"operation"]; NSString* status =nil; switch ([item_json[@"status"] intValue]) { case TaskStatusStart: status=@"uploading"; break; case TaskStatusStop: status=@"stop"; break; case TaskStatusError: status=@"warning"; break; case TaskStatusWait: status=@"waiting"; break; case TaskStatusFinish: status=@"finish"; break; default: status=@"warning"; break; } double progress =[item_json[@"progress"] doubleValue]; cell.progress = progress; cell.orderID = item_json[@"order"]; cell.action = item_json[@"action"]; cell.status = status; cell.errMsg = item_json[@"msg"]; cell.datetime = item_json[@"time"]; cell.photoName = item_json[@"name"]; op.updateUI=^(){ NSString* status =nil; switch ([item_json[@"status"] intValue]) { case TaskStatusStart: status=@"uploading"; break; case TaskStatusStop: status=@"stop"; break; case TaskStatusError: status=@"warning"; break; case TaskStatusWait: status=@"waiting"; break; case TaskStatusFinish: status=@"finish"; break; default: status=@"warning"; break; } double progress =[item_json[@"progress"] doubleValue]; cell.progress = progress; cell.orderID = item_json[@"order"]; cell.action = item_json[@"action"]; cell.status = status; cell.errMsg = item_json[@"msg"]; cell.datetime = item_json[@"time"]; cell.photoName = item_json[@"name"]; }; return cell; } - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { ApexDriverUploadCell *upCell = (ApexDriverUploadCell *)cell; AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate; NSUInteger row = indexPath.row; NSUInteger count = Appdelegate.uploadManager.arr_queue.count; if (count > row) { NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row]; RAUploadOperation* operation = item_json[@"operation"]; ApexDriverUploadCell *newCell = (ApexDriverUploadCell *)[tableView cellForRowAtIndexPath:indexPath]; if (newCell != upCell) { // reload row } else { operation.updateUI = nil; // restart 会调用就会导致cell不会刷新 } } [upCell reset]; } @end