How many app delegates can an iPhone app contain?

Discussion in 'iOS Programming' started by HawaiiMacAddict, Jan 4, 2010.

  1. HawaiiMacAddict macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #1
    Aloha everyone,

    I am a little bit confused at this point. To explain, I have a working app prototype (although data entry is still incomplete at this time), which contains a navigation controller and a tabbar controller. I have a credits view that lists contributors to my app and I wanted to provide a link to several pages.

    To that end, I have buttons that call up Safari, but before Safari is invoked, my app quits. I was looking into using a webview so that the user doesn't have to leave my app to view the webpages.

    Here's my question. Would I have to create a second app delegate for the webview? I'm not sure how to proceed at this point, but wanted to get some sort of consensus before I screwed everything up :D

    I've looked at Apple's documentation and it states that you can call up a webview by calling it up via a subview call from the app delegate. My problem is that due to the integration of my navigation and tabbar controllers, the app delegate provided when the project was created already has a subview call, which provides the first view presented to the user.

    I haven't asked this question before, but how many app delegates can an iPhone app have? I appreciate any responses received. Thank you in advance for any and all responses.

    HawaiiMacAddict
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    The short answer to your question is an app can have only one app delegate.

    You're confusing a view controller with an app delegate. Admittedly there are some similarities.

    In order to show a web view in your app you want a view controller that controls a web view. Show your web view from one of the tabs. Push it onto a nav controller if that works with your UI. But it will just be a normal view controller.
     
  3. HawaiiMacAddict thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #3
    Aloha PhoneyDeveloper,

    Nice account name, btw :D I thought an app could only have on app delegate, but got a little bit confused by Apple's documentation, unless they assumed that we would have only the web view, as is the case with online tutorials.

    Here's a question - I have a view containing buttons that I currently use to call up Safari, as shown in the attachment. Here is the code I'm currently using for this call (the buttons all use the same code, but with different URLs):

    Code:
    - (IBAction)pressMe2:(id)sender {
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.wikipedia.org"]];
    }
    
    You are saying that I can use this view controller to call up another view controller (the webview) to display that URL, right? I'll have to change the code for the method, of course, but I can research that part of it.

    With respect to your last suggestion, the view controller in the attachment activated via the second tab on the tabbar, so I'll most likely end up adding a second navigation controller for the webview.

    Thanks again for your response.
     

    Attached Files:

  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Right, one view controller can create and push another view controller onto a navigation controller.

    You should look at Settings.app and think about how it implements all the different views. Download some free apps from the app store. Many games are a little different and add and remove views directly from the screen but most other apps will use navigation controllers and tab bar controllers to add and remove views, each one controlled by a view controller, from the screen.

    You should of course read apple's view controller programming guide also.
     
  5. HawaiiMacAddict thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #5
    Aloha PhoneyDeveloper,

    I was not aware that I could treat a uiwebview as any other view. Obviously, I haven't used uiwebview before. I have downloaded the view controller programming guide, so I'll go through that today. It's really nice to know that what I've done with the other tab (and its embedded navigation controller) I can also do with this one. I should just have to create the views (uiwebviews) for the desired links (or find a way to pass on the URL so that only one is needed).

    Thanks again for your assistance. It is truly appreciated.
     
  6. HawaiiMacAddict thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #6
    btw, I created a PDF detailing the way I created the integration of navigation controllers within a tabbar controller. Please take a look and let me know if I got off in the wrong direction. It works, but if I'm doing something incorrectly, or if there is a better way to accomplish the same task, please let me know.

    As always, thanks in advance for your response.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    UIWebView inherits from UIView so, yes, you most definitely can.
     

Share This Page