0

i have a View Controller with a huge stack of Images in an Array. When i press the Button that takes me to View Controller it takes about 8-15 Seconds to load. Now I want to make a Loading screen so every time the app start, the View controller should be loaded in background.

How can I do this?

Thanks!

Shabbir Ahmad
  • 615
  • 7
  • 17
Victor Lobe
  • 355
  • 3
  • 12

3 Answers3

3

The best way to do that, relating to the final user experience, is using an Activity Indicator.

You should add it normally to your ViewController and relating it to your swift viewController'file.

When the loading will start, you must start to "spin" your activity indicator: in this way the user "understand" that "something will be loaded in a while".

When the loading will be finished, you must just make it hidden.

Moreover, if you want to be sure that images will be added after the loading of the view controller itself, load them through the viewWillAppear method, NOT viewDidLoad!

Istorn
  • 485
  • 1
  • 5
  • 23
2

don't load image in ViewDidLoad()

use this to load image

DispatchQueue.main.async {

}
Abdelahad Darwish
  • 5,969
  • 1
  • 17
  • 35
2

Hope this will help you for background queue and main queue operation !!!!

func bgQueue(queueName: String, completion codeBlock: @escaping ((Bool) -> Void)) {

        DispatchQueue.global(qos: .background).async {
            codeBlock(true)
        }
    }

func mainQueue(codeBlock: @escaping ((Bool) -> Void)){
        DispatchQueue.main.async {
            codeBlock(true)
        }
    }
  • 1
    Methods should start with lowercase letter in Swift. – Eric Aya Aug 22 '17 at 10:12
  • by the way, why should methods start with a lowercase letter? – Victor Lobe Aug 22 '17 at 10:31
  • 1
    Guys its coding standard, not compulsory !!!! or it's not going to give you any kind of compile or run time error ... – Bhavesh Patel Aug 22 '17 at 10:35
  • 1
    Sure, Bhavesh, but coding standards are not there just to be there. They serve a purpose. If you ignore the standards your code looks funny (or even wrong) to everyone else. Don't isolate yourself. Follow the standards. :) – Eric Aya Aug 22 '17 at 11:02