简体   繁体   中英

Data in tableView aren't displayed until I tap on tableView

could you please help me out

I'm implementing OAuth application:

  • user is authorizing via webView that is opened from code and from code is being closed
  • then 2 requests are sent in background - one request for token and second for data
  • then received data should appear on screen in tableView
  • all data are received back via blocks as all requests are asynchronous
  • and when data are received into tableViewController - I call reloadData method for table
  • main problem is that data appears in table only when I tap on table (in any place) . As soon as I understand the problem is with the way how webView appears and disappears, but can't fix it.

This is the way how webView is being called:

    CGRect rect = self.view.bounds;
    rect.origin = CGPointZero;
    UIWebView *webView = [[UIWebView alloc] initWithFrame:rect];
    webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.view addSubview:webView];
    self.webView = webView;

This is the way how webView is being closed:

        self.webView.delegate = nil;
        if (self.completionBlock) {
            self.completionBlock(dict);
        }
        [self dismissViewControllerAnimated:YES completion:nil];

This is the method that receives data in tableViewController:

- (void)loginButtonPressed:(UIButton *)button {
    [[ServerManager sharedInstance] authorizeUser:^(NSArray *data) {
        self.demoDataArray = data;
        NSLog(@"%@", self.demoDataArray);

        [self.tableView reloadData];

        NSArray *subviews = [self.view subviews];
        for (UIView *subview in subviews) {
            if (subview.tag == MY_CUSTOM_TAG) {
                [self.view bringSubviewToFront:subview];
            }
        }

    }];
}

I even tried to bring tableView as subview to front - but it doesn't work too

Sorry I Cant comment yet because I do not have enough reputation, but like Sandeep mentioned you must reload the table view on main thread After the data has been loaded with dispatch_async(dispatch_get_main_queue()). Have you checked this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM