Unable to update UITableView

后端 未结 2 2029
小鲜肉
小鲜肉 2021-02-03 15:02

I have UITableViewController as the RootViewController. I need to add rows to the table depending on data I get from another thread which I initiate from the RootViewController\

2条回答
  •  借酒劲吻你
    2021-02-03 15:47

    hey are you sure you are updating the table view display / reloading tableview on the main thread? i faced the same problem, the data was in there but until user scrolls, tableview was not updated

    upon googling i came to know you need to call the reloadData method on the main ui thread

    code example below:

    - (void) getDataOnNewThread
    {
        // code here to populate your data source
        // call refreshTableViewOnMainThread like below:
        [self performSelectorOnMainThread:@selector(refreshTableView) withObject:nil waitUntilDone:NO];
    }
    
    - (void) refreshTableView
    {
        [tableView reloadData];
    }
    

提交回复
热议问题