Christian
Christian

Reputation: 22353

Add subview before calling method

I've got a really strange problem. First my code:

func viewDuringLoading(){
        var tabBarSize = self.tabBarController?.view.bounds.size

        hider = UIView(frame: CGRectMake(0, 0, tabBarSize!.width, tabBarSize!.height))
        hider.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)


        indicator = UIActivityIndicatorView(frame: CGRectMake(hider.bounds.width/2 - 25, hider.bounds.height/2 - 25, 50, 50))

        indicator.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.6)

        hider.addSubview(indicator)
        indicator.startAnimating()

        self.tabBarController?.view.addSubview(hider)

        checkProducts()

    }

As you see, I add a subview to my view and after that I call my non async method checkProducts. My problem now is, that the subview get added to my view after my checkProducts finished doing the work.

How can I resolve that problem? I've thought about using an async-thread. But it doesn't seem to work.

Upvotes: 0

Views: 58

Answers (1)

Aaron Wojnowski
Aaron Wojnowski

Reputation: 6480

Depends what you do in checkProgress. Based on what you're saying, it sounds like checkProgress is a synchronous method that blocks the main thread, which stops your view from being added as a subview.

What does the method checkProgress do? What happened when you ran it asynchronously? If it blocks the main thread at all, it probably should be asynchronous regardless of whether it blocks the main thread or not.

Upvotes: 1

Related Questions