Thanh Nguyen Thanh Nguyen - 1 year ago 64
Objective-C Question

What's best way to display default view for 'No internet connection' each time navigate to any of view controllers?

If inserting the snippet code for checking and displaying the default view in the case of no internect connect at the beginning of viewWillAppear: method of each view controllers, it would make the ton of boilerplate code. So, I'd like to ask:

  1. Is there a way to centralize this snippet code in one place and automatically inject into any of view controllers right after be called to display.

  2. In the case of no internet connection, how to display the default view instead of the view of view controller?

Answer Source
  1. First you have a to create a seperate view for 'No Internet screen'.
  2. Create a BaseViewController in which, you will a a logic of hide/show no internet screen.
  3. And all your apps viewcontroller are derived from this 'BaseViewController' and initialize this 'No Internet screen' and hide/show depends of internet Or API fails

Thats it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download