在调用方法之前添加子视图

时间:2015-02-01 22:00:20

标签: swift subview

我有一个非常奇怪的问题。首先是我的代码:

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()

    }

如您所见,我在视图中添加了一个子视图,之后我调用了我的非异步方法checkProducts。我现在的问题是,在checkProducts完成工作后,子视图会添加到我的视图中。

我该如何解决这个问题?我考虑过使用异步线程。但它似乎没有用。

1 个答案:

答案 0 :(得分:1)

取决于您在checkProgress中的操作。基于你所说的,听起来checkProgress是一种阻止主线程的同步方法,它阻止你的视图被添加为子视图。

方法checkProgress有什么作用?你异步运行它时发生了什么?如果它完全阻塞主线程,它可能应该是异步的,无论它是否阻塞主线程。

相关问题