2

I use Apple's Reachability class and it's working fine using an alert to tell the user that the connection is not available or the connection is lost. However, I want to change the alert to something more visual. I want to load a nib that tells the user no active connection is present but the nib is not loading. I also tried loading my other nibs but it also doesn't load the nib.

- (BOOL) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes

NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)

{
    case NotReachable:
    {
        NSLog(@"The internet is down.");
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Internet Connection" message:@"You are currently not connected to a WI-FI or cellular Data.\nPlease make sure you are connected." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];

        //NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
        //[self presentModalViewController:noConn animated:NO];
        //[NoConnection release];

        self.isConnected = NO;
        return NO;
        break;

    }
    //more cases.........

the alert part is working just fine but the part for loading the nib is not. can you tell me whats wrong here? I'm calling this function in viewWillAppear. Thanks!

Diffy
  • 735
  • 1
  • 15
  • 34
  • Does the code work in any other place like viewwillapper? – Radu Sep 09 '11 at 07:37
  • i tried in viewDidDLoad and didn't work either. i get the alert though but not the nib. – Diffy Sep 09 '11 at 07:39
  • it is clear you have a problem in the nib file open the nib file and look to se if everything is in order, inspecialy lookat the file's new owner class,at custom class, – Radu Sep 09 '11 at 07:43
  • if that doesn't work and your in a hurry, you could create a diffrent view to open instead of the same view whit diffrent nib file. It's not quite recommended but should work – Radu Sep 09 '11 at 07:46
  • try this [self.navigationController presentModalViewController:detailView animated:YES]; – Radu Sep 09 '11 at 08:20

4 Answers4

0

You need to use the delegate method of alert view

#pragma mark - AlertView Delegates

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1)
        {
            NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
            [self presentModalViewController:noConn animated:NO];
            [NoConnection release];
        }
}

don't forget to assign tag value of alertView to 1.

and also dont forget to conforms to the UIAlertViewDelegate protocol

Happy Coding :)

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
0

You can do the following:

if ( ! isConnected )
{
    NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
    [self presentModalViewController:noConn animated:NO];
    [NoConnection release];
}
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • I already have that but it doesn't show up, I just commented it to test via alert. – Diffy Sep 09 '11 at 07:34
  • Do not use it in the `checkNetworkStatus:`, use it in another method, maybe an `IBAction` / button press, or `viewWillAppear:` – WrightsCS Sep 09 '11 at 07:36
0

The code you have presented should work, sow the problem must be somewhere else probably in the nib - linking, you might have forgot to link something to the nib file. try this

    [self.navigationController presentModalViewController:noConn animated:YES];  
Radu
  • 3,434
  • 4
  • 27
  • 38
  • the NoConnecton nib should be just fine. It's only a view that contains an image. I tried calling my NoConnecton nib in my other class and it loads just fine, so the nib is okay right? what I did now is I load a different nib(w/c loads just fine in my other classes) on the same method but the view won't show up. – Diffy Sep 09 '11 at 07:50
  • still no luck with [self.navigationController presentModalViewController:noConn animated:YES]; – Diffy Sep 09 '11 at 08:33
  • The class you are implementing the presentModalView call is it a UIVIewController ? – Radu Sep 09 '11 at 08:43
  • yes it is a uiviewcontroller. if it's not then it should display a warning, but i implement this in a uiviewcontroller. – Diffy Sep 09 '11 at 09:04
  • I'm stomped very strange bug, – Radu Sep 09 '11 at 09:10
0

Does your nib has NoConnection as a File's Owner (I guess NoConnection is a subclass of UIViewController, check it. I'll call this NoConnectionViewController bellow because you should name it like that for no mistake) ?

Is the file's owner view property linked with the graphical view ? Check it.

Are you working without status bar at top of the window ? That could be a problem.

Are your here inside a modalViewController ? If yes, your code won't work, you must use instead :

    NoConnectionViewController* nextWindow = [[NoConnectionViewController alloc]  initWithNibName:@"NoConnecton" bundle:nil];  // Check your nib name here, seems to be a mistake
    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
    [self presentModalViewController:navController animated:YES];
    [navController release];
    [nextWindow release];
Oliver
  • 23,072
  • 33
  • 138
  • 230