ios - 事件指示器未出现

标签 ios objective-c swift xcode

 override func viewDidLoad()
        {
            super.viewDidLoad()

            if self.revealViewController() != nil
            {
                menuButton.target = self.revealViewController()
                menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
                self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
            }



         Server.fetchCampaignList(target: self)


        let indicator = UIActivityIndicatorView(activityIndicatorStyle: .white)
        indicator.center = self.view.center
        indicator.startAnimating()
        self.view.addSubview(indicator)

    }

我已经阅读了很多答案,但仍然不明白我做错了什么。我的以下函数位于 TableViewController 类中。我想在调用 viewDidLoad 方法后立即显示事件指示器。在相同的方法中,我必须从服务器获取列表,当收到数据时,同一类中的 nextAction 方法被调用并且正在重新加载表。

一切正常。但事件指示器没有出现。

最佳答案

我已经在主线程中添加了指标代码并且它出现了。我会要求一些高级开发人员解释如果没有它会出现什么问题以及为什么现在它可以这样工作。这对以后的迟到者有帮助。

override func viewDidLoad()
    {
        super.viewDidLoad()

        if self.revealViewController() != nil
        {
            menuButton.target = self.revealViewController()
            menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
            self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }

        OperationQueue.main.addOperation
            {
                Server.fetchCampaignList(target: self)
                let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
                indicator.center = self.view.center
                self.view.addSubview(indicator)
                indicator.startAnimating()
        }
    }

关于ios - 事件指示器未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39825861/

相关文章:

ios - 更新应用程序后,应用程序在 sqlite 上崩溃

ios - HLS 流式传输到 IOS 设备

iOS 8.1 : Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'

objective-c - xcode 'NSInvalidArgumentException',原因: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'

ios - Swift 中使用 numberOfRowsInSection 的 void 函数出现意外的非 void 返回值

xcode - 为什么 viewDidLoad 在 didSelectItemAtIndexPath 之前运行?

cocoa - Swift如何安排一段代码在下一个runloop中执行?

ios 如何在 ViewController 中模拟后退按钮

ios - 重新编译现有的 objective c 库以支持 arm8

ios - 如何在 iOS(例如 iPhone)中保存 .plist 文件?