我在服務器上上傳文件並在標籤上顯示percention,標籤位於表格單元格內,但當我們導航到另一個視圖時,其停止更新,更新的百分比僅在顯示時顯示我們滾動表..導航到另一個視圖控制器時,標籤停止更新
-(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];
}
}
謝謝先生,但它不工作 –
是一次上傳單張圖片還是多張圖片? – arunit21