views:

59

answers:

1

I have a Tab Bar controller inside a Navigation controller. I want to create a view, with a single 320x411 image (leaving the status bar, and the tab bar).

The image is shown for a network connection error.

Currently I'm using this code, in the tab bar item's individual view's viewDidLoad:

if (appDelegate.hasInternetAtStart == NO) {
    CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
    UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
    [myImage setImage:[UIImage imageNamed:@"NetworkError.png"]];
    myImage.opaque = YES;
    [self.view pushViewController:myImage animated:NO];     
    [myImage release];
}

However this is allowing the elements below to be touched and accessed.

Is the right way to go about to show a error, or should I opt for another method.

I would like a single view, that will override all the other views in the tab bar item, and can be set in App Delegate if possible...

+2  A: 

Have you tried launching your UIImageView from within the App Delegate?

Doing this, make the view and your image the size of the whole screen. By using a PNG transparency image, your error will display without allowing the user to touch the NavController tab bar.

If you want to trigger this from outside the App Delegate, you can use the NSNotificationCenter to create a responder in the App Delegate like this.

// Register listener 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNetworkError) name:@"showNetworkError" object:nil];

And call it from outside the appDelegate like this:

// Post notification 
[[NSNotificationCenter defaultCenter] postNotificationName:@"showNetworkError" object:self];

Note that the selector "showNetworkError" is the name of the function that displays the error UIImageView.

crunchyt
Nice!! I got it working for covering up the whole screen. Thanks..Now I'm trying to show it with the Status Bar + Navigation Bar + Tab Bar controllers. But I got it working atleast...
Swizzy