NSURLSessionDataTask not executing the completion handler block

后端 未结 2 1367
广开言路
广开言路 2021-01-04 20:46

I am trying to pull some data from my local node server. The server is getting the get request and logging it, but for some reason my iOS app will not execute any of the cod

2条回答
  •  無奈伤痛
    2021-01-04 21:24

    NSURLSessionDataTask runs in a background thread. To update anything in the user interface such as labels, buttons, table views, etc, you must do so on the main thread. If you want to update the label text from the completionHandler block then you need to update the label in the main thread like so:

    dispatch_sync(dispatch_get_main_queue(), ^{
      nameLabel.text = @"yay!";
    });
    

提交回复
热议问题