保存数据后表视图不重新加载

时间:2016-09-22 16:31:20

标签: ios objective-c uitableview

我已经使用表格视图创建了一个基本的聊天应用程序。当我的用户点按“发送”按钮时按钮将消息传递给另一个用户,我希望此表视图刷新,以便实时显示消息。也就是说,我放置[self.tableView reloadData]的地方目前似乎没有完成任务。请参阅以下代码:

- (IBAction)sendReply:(id)sender {


    NSMutableDictionary *nodeData = [NSMutableDictionary new];

    [nodeData setObject:@"messages" forKey:@"type"];


    NSDictionary *messageValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:self.replyText.text, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
    NSDictionary *finalMessage = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:messageValues] forKey:@"und"];

    [nodeData setObject:finalMessage forKey:@"body"];

     NSString *otherUID = [self.messageData objectForKey:@"targetuser"];


    NSString *userValue = otherUID;

    NSDictionary *targetMessage = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:userValue, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
    NSDictionary *finalUser = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:targetMessage] forKey:@"und"];

    [nodeData setObject:finalUser forKey:@"field_targetuser"];

    [nodeData setValue: @"Re:" forKey:@"title"];


    NSString *uid = [[[DIOSSession sharedSession] user] objectForKey:@"uid"];


    [DIOSNode nodeSave:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {


          [self.tableView reloadData];


        MessageSentViewController *sentView = [[MessageSentViewController alloc] init];
        [self presentViewController:sentView animated:YES completion:nil];



    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Node did not save!");
    }];


}

1 个答案:

答案 0 :(得分:-1)

尝试在main / seprate线程上重新加载tableview