2

On my initial view (Tab bar controller that loads a navigation controller) I check for internet connection. If the device has no active connection, I load a view that says Active Internet connection is required and has a retry button.

My problem is this: Since the initial view is navigation based, and by using the following code, I load the warning view, there is a back button to the initial view. So by pressing the back button, one can go back to the initial view, which is empty because it requires connection to display its content. So loading a view does not seem to be a solution in my case. Also by clicking the retry button, the user is sent back to initial view which again loads the alerter view. which goes into a crazy loop, with recurring navigation bars.

here is my redirect code:

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([Connection isConnected]) {NSLog(@"connected");}
    else {
        Alerter *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Alerter"];
        [self.navigationController pushViewController:controller animated:NO];

    }

Can anyone recommend a better way to handle this?

Savaş Zorlu
  • 85
  • 10

2 Answers2

1

You could check for reachability before loading the navigation controller, and if there is no internet connection show a UIAlert view with your message.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • Thanks for the advice but I wanted to use a view because UIalert view is not looking so nice. But I think it is a good idea to do this before the navigation controller. – Savaş Zorlu Dec 26 '11 at 10:12
  • So? Pop up a modal view instead of a UIAlert view. The point is that you have the controller check whether the network is reachable and either show a navigation controller or a different view. – Abizern Dec 26 '11 at 12:43
0

You can always hide back button of the Alerter view controller, so that user does not leave it unless there's an internet connection [self.navigationItem setHidesBackBarItem:YES];

dariaa
  • 6,285
  • 4
  • 42
  • 58
  • Or perhaps you can present it as a modal view controller. – dariaa Dec 24 '11 at 15:31
  • As for hiding the back button, it would solve the issue to some extent. but repetitive nab bars is the other issue. I think there must be another way to handle this; instead of loading views. – Savaş Zorlu Dec 24 '11 at 15:47