Tableview重新加载数据在使用afnetworking 2时不起作用?

时间:2016-06-10 09:45:38

标签: ios objective-c uitableview afnetworking-2

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager GET:[NSString stringWithFormat:@"%@%@",TIC_URL,@"list_messages.php"] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"responseObject %@",responseObject);
     if (![[responseObject valueForKey:@"status"] isEqualToString:@"0"]) {
         marrChat = [responseObject valueForKey:@"data"];

         [self.tblChat reloadData];


         if (marrChat.count > 0)
         {
             [self.tblChat scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:marrChat.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
         }

     } 

     failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     NSLog(@"Error %@",error);
     [CommonFunctions showNoNetworkError];
     HideHUD;
 }];

2 个答案:

答案 0 :(得分:0)

[self.tblChat reloadData];写入主队列。

    dispatch_sync(dispatch_get_main_queue(), ^{
    [self.tblChat reloadData];

});

答案 1 :(得分:0)

试试这个:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView performWithoutAnimation:^{
        [cell layoutIfNeeded];
    }];
}