简体   繁体   中英

UIView screen freeze when calling dispatch_async(dispatch_get_main_queue())

I have a popup which need to be show until all the images are uploaded on the view controller, I use dispatch-async method to show the popup before all the images are uploaded and hide as the images display.

But the UIView screen freezes displaying hang popup on calling dispatch_async method where I was wrong in the code or whats the best way to achieve this.

func imageIconTapped(gesture: UITapGestureRecognizer){
        self.loadingPopUp = showPopUp(self, txt: “Processing..")
        self.navigationController!.view.addSubview(self.loadingPopUp!)

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {

           code to getting the image   // getting the images is time taking therefore it work in the background. 

            dispatch_async(dispatch_get_main_queue()) {                

        method to upload the images on the view controller and hide the popup.            
        }

The function "imageIconTapped" is UIKit method which is already run on main thread.So no need to dispatch code to main queue.

Main thread is block when you dispatch code from main thread to main queue.

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