Interface Builder and URL's

Discussion in 'Mac Programming' started by Switz213, Jun 3, 2008.

  1. Switz213 macrumors 6502

    Joined:
    May 26, 2008
    #1
    I want to recreate the Safari menu. I figured out how to make new drop-downs and stuff, but how can I set those to go to a specific site? I have never used IB before, but I am pretty good with coding in general.

    Thanks,
    Switz
     
  2. Switz213 thread starter macrumors 6502

    Joined:
    May 26, 2008
    #2
    Anyone?

    For more detail. When you click on a drop down, it drops down, then click on a button and it goes to a website.

    Thanks in advance
     
  3. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #3
    Uhm, IB doesn't write code for you. It makes it easier to link UI elements to your code, but to actually do something you have to write some code to open the URL.

    Code:
        BOOL  success;
        NSURL  *moreInfoURL = [[NSURL alloc] initWithString:@"http://www.dhs.gov/dhspublic/"];
    
        success = [[NSWorkspace sharedWorkspace] openURL:[moreInfoURL absoluteURL]];
    That opens a URL. You link that to your menus or whatever, and then it will open a URL when you select it.
     
  4. Switz213 thread starter macrumors 6502

    Joined:
    May 26, 2008
    #4
    Thanks,
    where would I go about editing that in?

    Thanks
     
  5. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    in your appController.m file (or where ever) write:

    Code:
    -(IBAction)thisIsYourURLButtonMethod:(id)sender
    {
    BOOL  success;
    NSURL  *moreInfoURL = [[NSURL alloc] initWithString:@"http://www.dhs.gov/dhspublic/"];
    
    success = [[NSWorkspace sharedWorkspace] openURL:[moreInfoURL absoluteURL]];
    [moreInfoURL release];
    }
    
    declare the method in appController.h file

    then open Interface Builder (or save / build Xcode project if IB is already open so that IB will be in-sync with Xcode), drag a connecting line from your button (that you wanna use to trigger the website) to your appController object, and select "thisIsYourURLButtonMethod"...

    easy as pie...
     

Share This Page