Reputation: 213
I am trying to link my code to my GUI. But it won't let me.
Currently, I have a label, Button, and a Text Field on my GUI. This is my code for the GUI:
-- IBOutlets
property window : missing value
on buttonClicked_(sender)
display alert "Hello there " & (stringValue() of textField)
end buttonClicked_
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
When I try using the App Delegate tool, It doesn't work. I drag it to the parts on the GUI and it makes a blue line. But, The only thing the shows up under "Outlets" is "Window"
If I run the program, The GUI comes up, but it doesn't do anything cause the code isn't connected!
How do I connect my code to my GUI?
Extra Info: Xcode 5.1
Upvotes: 1
Views: 1663
Reputation: 1548
You have to declare the outlet and then connect the outlets in the xib. ctrl-drag (or click right mouse button and drag) from AppDelegate to the textfield. Then ctrl-drag from the button to the AppDelegate and choose the method, you want to send.
-- IBOutlets
property window : missing value
property myTextField : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on buttonClicked_(sender)
display alert "Hello there " & myTextField's stringValue
end buttonClicked_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
Upvotes: 3