2016-08-19 8 views
1

私はサーバにファイルをアップロードしてラベルにパーセントを表示していますが、ラベルはテーブルのセルにありますが、別のビューに移動すると、我々はラベルは別のビューコントローラにナビゲートすると更新が停止します

enter image description here

-(void)sendReplyOnServer:(NSMutableDictionary*)params 
     withMessage:(Message*)sendMessage 
      withIndex:(NSUInteger)deliveredIndex { 


[self addReplyInDiscussion:sendMessage.disscussionId]; 

[[APIClient sharedClient] postReply:params andBlock:^(NSDictionary *responseDictionary, 
                 NSError *error) { 
    @try { 

     [[DataManager sharedManager].sendMessages removeObject:sendMessage]; 

     if (!error){ 


      NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary :[[responseDictionary objectForKey:@"response"] objectForKey:@"data"] ]; 
      // [dict setObject:@"0" forKey:@"message_status"]; 

      NSLog(@"%@",dict); 

      Message *deliveredMessage = 
      [Message modelObjectWithDictionary:dict]; 

      if ([[responseDictionary objectForKey:@"response"] objectForKey:@"document"]){ 

       Document *doc = [Document modelObjectWithDictionary:[[responseDictionary objectForKey:@"response"] objectForKey:@"document"]]; 

       if ([DataManager sharedManager].documentListArray.count == 0){ 
        [DataManager loadDocumentList]; 
       } 
       if (![DataManager sharedManager].allDocumentsList){ 
        [DataManager sharedManager].allDocumentsList = [[NSMutableArray alloc] init]; 
       } 

       NSString *documentID = @"1"; 
       NSPredicate *predicate = [NSPredicate predicateWithFormat:@"documentId == %@",documentID]; 
       NSArray *filteredArray = [[DataManager sharedManager].documentListArray filteredArrayUsingPredicate:predicate]; 
       if (filteredArray.count != 0) { 
        Document *cameraRoll = [filteredArray objectAtIndex:0]; 
        doc.parent = cameraRoll; 
        [cameraRoll.documents addObject:doc]; 
       } 
//     Document *cameraRoll = [[DataManager sharedManager].documentListArray objectAtIndex:1]; 
//     [cameraRoll.documents addObject:doc]; 

       [[DataManager sharedManager].allDocumentsList addObject:doc]; 
       [DataManager serializeDocumentList]; 
       [DataManager serializeallDocumentList]; 

      } 

      //              if ([ deliveredMessage.deliveryStatus isEqualToString:@"1" ]) { 
      deliveredMessage.deliveryStatus = @"2"; 

      //image save in file 
      // deliveredMessage.attachment.image = sendMessage.attachment.image; 

      if(sendMessage.attachment.image) { 


       deliveredMessage.attachment.image = sendMessage.attachment.image; 

       NSURL *url = [NSURL URLWithString:deliveredMessage.attachment.fileName]; 
       NSString *name = [url lastPathComponent]; 

       NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
       NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:name]; 
       // NSLog(@"my path == %@",path); 
       NSData * binaryImageData = UIImagePNGRepresentation(sendMessage.attachment.image); 

       [binaryImageData writeToFile:path atomically:YES]; 
      } 

      // } 

      if ([sendMessage.disscussionId isEqualToString:disscussionId]) { 


       [self updateMessageList:deliveredMessage withIndex:deliveredIndex withSendMessage:sendMessage]; 

      } else if ([disscussionId isEqualToString:@""]) { 
       NSLog(@"reached in known"); 

       NSString *string = [NSString stringWithFormat:@"dataIdentifier == %@ ",sendMessage.disscussionId]; 

       NSPredicate *predicate = [NSPredicate predicateWithFormat:string]; 

       NSArray *filterArray = [[DataManager sharedManager].chatListArray filteredArrayUsingPredicate:predicate]; 

       if (filterArray.count != 0) { 

        DiscussionData *discussionOject = [filterArray objectAtIndex:0]; 
        NSUInteger indexOfManager = [[DataManager sharedManager].chatListArray indexOfObject:discussionOject]; 
        DiscussionData *managerDiscussionOject = [[DataManager sharedManager].chatListArray objectAtIndex:indexOfManager]; 
        string = [NSString stringWithFormat:@"identifier == \"%@\" ",deliveredMessage.identifier]; 

        predicate = [NSPredicate predicateWithFormat:string]; 
        filterArray = [managerDiscussionOject.replies.data filteredArrayUsingPredicate:predicate]; 

        if (filterArray.count != 0) { 

         NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init]; 

         NSUInteger idx = 0; 
         for (Message *message in managerDiscussionOject.replies.data) { 
          if ([message.identifier isEqualToString:deliveredMessage.identifier] && [message.identifier isEqualToString:message.internalBaseClassIdentifier]){ 
           [indexes addIndex:idx]; 

          } 
          idx ++; 
         } 

         [managerDiscussionOject.replies.data removeObjectsAtIndexes:indexes ]; 

         [[NSNotificationCenter defaultCenter] 
         postNotificationName:UPDATE_REPLY_ARRAY 
         object:managerDiscussionOject]; 

        } 


              //[DataManager serializeChatList]; 
       } 
       //This case will be handle when time is same 
      } 
      else { 

       /* NSString *string = [NSString stringWithFormat:@"dataIdentifier == %@ ",sendMessage.disscussionId]; 

       NSPredicate *predicate = [NSPredicate predicateWithFormat:string]; 

       NSArray *filterArray = [[DataManager sharedManager].chatListArray filteredArrayUsingPredicate:predicate]; 

       if (filterArray.count != 0) { 

       DiscussionData *discussionOject = [filterArray objectAtIndex:0]; 
       NSUInteger indexOfManager = [[DataManager sharedManager].chatListArray indexOfObject:discussionOject]; 
       DiscussionData *managerDiscussionOject = [[DataManager sharedManager].chatListArray objectAtIndex:indexOfManager]; 


       [DataManager serializeChatList]; 
       }*/ 

      } 



     }else { 
      NSLog(@"chat reply error === %@",error.localizedDescription); 
      sendMessage.deliveryStatus = @"3"; 

      if ([sendMessage.disscussionId isEqualToString:disscussionId]) { 

       if (repliesArray.count != 0) { 

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[self indexOfReplyId:sendMessage.internalBaseClassIdentifier] inSection:0]; 
        //NSIndexPath *indexPath = [NSIndexPath indexPathForRow inSection:0]; 
        ChatDetailBaseTVC *cell = (ChatDetailBaseTVC *)[self.tableViewChatConv cellForRowAtIndexPath:indexPath]; 
        cell.msgDeliveryStatusImageView.image = [UIImage imageNamed:MESSAGE_RETRY_IMAGE]; 
        cell.status = @"3"; 

        if (sendMessage.attachment) { 
         [cell.fileNameLabel setTitle:[NSString stringWithFormat:@" %@", cell.messageObj.attachment.title ] forState:UIControlStateNormal]; 
         cell.progressValue = 0.0 ; 
         sendMessage.attachment.progress = @"0%"; 
        } 
        [self updateContentInsetForTableView:self.tableViewChatConv animated:NO]; 
        [self addReplyInDiscussion:sendMessage.disscussionId]; 

       } 
      } 


     } 
    }@catch(NSException *e) {} 

} showSpinner:YES showProgressView:^(float progress, NSString *messageId) { 

    [self updateCellProgress:progress :messageId :sendMessage]; 


}]; 
} 



-(void)updateCellProgress:(float) progress :(NSString *)messageId :(Message*)sendMessage{ 

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[self indexOfReplyId:messageId] inSection:0]; 
ChatDetailAttached *cell = (ChatDetailAttached *)[self.tableViewChatConv cellForRowAtIndexPath:indexPath]; 

cell.messageObj.attachment.progress =[NSString stringWithFormat:@"%.0f%%",progress]; 
NSLog(@"indx %ld == message id %@ progress == %@", (long)indexPath.row, messageId,cell.messageObj.attachment.progress); 

if ([cell isKindOfClass:[ChatDetailAttached class]] && 
    [sendMessage.internalBaseClassIdentifier isEqualToString:cell.messageObj.internalBaseClassIdentifier]) { 

    [cell.fileNameLabel setTitle:[NSString stringWithFormat:@" %@ %@",cell.messageObj.attachment.progress, cell.messageObj.attachment.title ] forState:UIControlStateNormal]; 
} 

} 

答えて

0

は、メインスレッドでセルを更新するようにしてください..テーブルをスクロールします。ブロックを使用しているときはブロック変数を使用します。アップロードがuploadIndexへのセルのインデックス保存をクリックすると

  1. 、進捗状況を保持する変数を持ってCGFloat _progressNSIndexPath *uploadIndex
  2. リロードshowProgressViewのセル進歩は変数更新:次に細胞、cell.progressValue = _progressに進捗を更新cellForRowAtIndex、if([indexPath isEqual:uploadIndex])

     showProgressView:^(float progress, NSString *messageId) { 
          dispatch_async(dispatch_get_main_queue(), ^{ 
           _progress = progress; [self.tableViewChatConv reloadRowsAtIndexPaths:@[uploadIndex] withRowAnimation:UITableViewRowAnimationNone]; 
          } 
         } 
    
  3. をブロックします。

+0

ご協力ありがとうございます –

+0

一度に複数の画像をアップロードしていますか? – arunit21

0

はのviewDidLoadでNSTimerを入れてNSTimerのセレクタに動作方法を設定:

およびアクションmethode.gにtabelビューをリロード:[_mytableviewリロード]。

関連する問題