0

Well i want from the drop down menu(Menu Item List) one item to be working as an link, to open an url/website in safari - thats it. When this is so simple, why no one come up with a clue here - I tried many different ways in Xcode, with Apple Xcode Samples... i think i need an AppDelegate.m, drag or link some parts, get actions... i failed to get it going somewhere - now i'm lost. Any advice/help/link/tip would be much appreciate to solve this "simple" issue...

Using Xcode/Interface Builder 3.2.6 - Please help or i go totally mad, insane and i will crash my f...ing mac right now - Thanks

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
  • Can you post some more info, exactly what have you tried and why it has not worked? Also if you format your question better we will be able to understand your needs better – Deepend Jun 16 '12 at 18:35

1 Answers1

5

It should work if you just create an empty Cocoa project in Xcode and follow these steps:

First, in the interface section of your AppDelegate.h, enter this line:

    -(IBAction)openLink:(id)sender;

Second, in the implementation section of your AppDelegate.m, enter these lines:

    -(IBAction)openLink:(id)sender
    {
        [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];
    }

Third, make a connection between your method and the menu item. Do this in Interface Builder. There are several ways to do this, a simple one is first to click on the menu item you want to connect:

Step 1

Then head over to the connections pane at the right side of the IB window:

enter image description here

There click & hold on the small circle next to the description "selector" and drag the mouse to the left. It should look like this:

enter image description here

Move the mouse to the left until the pointer is over the "AppDelegate" item in the left part of IB:

enter image description here

Now (last step!) a little window will pop up asking you to which method of your AppDelegate you want to connect the menu item. Just click on the openLink: method, and you're done:

enter image description here

If you now run your program and click on the menu item you've connected to the openLink: method, the link will open in your default web browser (not necessarily Safari).

Tim
  • 1,659
  • 1
  • 21
  • 33