Help with adding an alert view to a tab bar application!

Discussion in 'iOS Programming' started by Patoma16, May 25, 2010.

  1. Patoma16 macrumors member

    Joined:
    May 19, 2010
    #1
    I submitted an application I made a couple days ago and it was rejected due to the fact of it not having an internet connection error, so if u weren't connected to the internet, it would not display an error. And, all the tutorials that i fin don't apply for my application. It doesn't WORK!!! my application has four tabs, with each tab displaying a UIWebView. I am trying for an alert view to pop up at the boot-up of the application that warns the user of having an internet connection, rather than adding the actual error once it doesn't load, but if any of you know to do the error message on a tab bar app like mine, that would be preferable! Thanks, and please help me, I am desperate!!!!!!!!!!

    Peace, Love, :apple: !!!!!!!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I'd look at the UICatalog sample app for how to code a UIAlertView.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    Look at the Reachability sample code from Apple. It shows how to check for internet connects.
     
  4. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #4
    Yah... I've done it, but it doesn't work! I suppose it due to it being a tab bar based application it has like 5 tabs. I've practically tried everything... But it doesn't work, like my guess is that the it doesn't know where to display it even though I placed the code in the FirstViewController.m Should I place the code in all the ViewControllers. But, really all I want is a little alert view to pop up on bootup (of the app) telling u to make sure u have an Internet connection.... So please someone help!
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    UIAlertView's are not tied to any view / viewController. They just pop-up. So, maybe you should be more explicit about what you've tried and what isn't working.
     
  6. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #6
    Well, I tried doing all the tutorials I can find on how to implement the Internet access check, but for some reason it doesn't work. But in the tutorial they would use a simple view based app, I created a tab bar based app, so, no tutorial worked. In the tutorials they would add the code in the view controller (the only view controller) but since I have a tab bar based app, I have 5 view controllers!!!!! So then I decided to just add a simple warning UIAlertView in the start of the app. So I added the alert view code, the one I used in the Internet checker, and again no results. I don't know where to add the code, or if I have the wrong code. But what would you do if you where in the same dispute as me, and please help me.... I need my app in the AppStore!!!
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    I'd post the code for your UIAlertView usage.
     
  8. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #8
    How?!? Like copy and paste. Well thank you in advance!
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Yes, copy and paste would be easiest and most accurate.
     
  10. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #10
    So, can u post the code?
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    No, what I meant was that if I were you, I'd post some code so that we can try to help you out. That is, you should post some code!
     
  12. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #12
    Okay, this is the code I used for the UIAlertView:

    Code:
    - (void)viewDidLoad {
        [super viewDidLoad];
    	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"This application requires an internet connection! If there is none present, all tabs will remain white" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    	[alert show];
    	[alert release];
    	
    }
    Note: I added this under the viewDidLoad, and in the FirstViewController of my five view controllers. So, now please help, the alert won't pop up, and as a reminder I want it to come up on the app's startup. Thanks in advance once again.
     
  13. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #13
    Did you try adding it to - (void)viewWillAppear: (BOOL)animated? Maybe the calling view needs to be visible for the alert to be seen.
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    I created a Tab Bar Application and changed the viewDidLoad to match yours. The alert pops up right upon app startup just fine. So, there must be something else you're doing that's causing this issue.

    By the way, I also added the alert to the app delegate's didFinishLaunching and it worked there too.
     
  15. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #15
    Wow it worked!!!!! I can't thank you enough!!! Wow!
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    Be careful with this solution. It may possibly cause the alert to appear much more frequently than once.
     
  17. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #17
    Yah I noticed, every time I go to the tab, the alert view pops up. But, since u said u where able to crerate the tab bar application with the alert view, I'll give u more details of how the app works. Every tab view has a UIWebView in it, two navigation bars (one at the top and one at the bottom) and a tool bar with the controls to go back, forward, refresh, and cancel refresh. And there are five tabs with the same layout. And the other way of doing through ViewDidLoad didn't work, so... Hopefully you can make something put of this?
     
  18. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #18
    Have you tried putting it in your app delegate?

    Edit: P.S. Two navBars and a toolbar, all inside a tab view? Is there even any room for content? :confused: ;)
     
  19. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #19
    What code do I put in the app delegate, the ViewDidLoad or ViewWillAppear? I tried both... And none worked. Still the only one that works is the ViewWillAppear on the FirstViewController... But it repeats the message every time you tap on the tab, it gets annoying.
     
  20. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #20
    For app delegate:
    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        
        // Add the tab bar controller's current view as a subview of the window
        [window addSubview:tabBarController.view];
        [window makeKeyAndVisible];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"This application requires an internet connection! If there is none present, all tabs will remain white" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    	
        return YES;
    }
    
    For FirstViewController.m:
    Code:
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"This application requires an internet connection! If there is none present, all tabs will remain white" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    Of course, all this is oversimplified to just invoke the alert. You'll still need all the smarts to check for an internet connection, once you get past this issue.
     
  21. Patoma16 thread starter macrumors member

    Joined:
    May 19, 2010
    #21
    Wow thanks! It finally worked without the annoying message! I can't thank you enough for taking your time to help me!
     

Share This Page