Activity Indicator is not appearing

Rais Iqbal
 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)

    }

I've read many answers but am still not getting what am I doing wrong. My following function is in TableViewController class. I want to show activity indicator as soon as viewDidLoad method get called. In same method I've to fetch a list from server, when data received my nextAction method in same class is getting called & the am doing reload table.

Everything is working fine. But Activity indicator is not appearing.

Rais Iqbal

I've added indicator code in main thread & it appeared. I'd request some senior developer to explain what was going wrong without it & why now it is working so that. It'll help late comers in future.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related