1

我正在尝试将我的代码链接到我的 GUI。但它不会让我。

目前,我的 GUI 上有一个标签、按钮和一个文本字段。这是我的 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_ 

当我尝试使用 App Delegate 工具时,它不起作用。我将它拖到 GUI 上的部件上,它会形成一条蓝线。但是,“Outlets”下唯一显示的是“Window”

如果我运行该程序,GUI 会出现,但它没有做任何事情,因为代码没有连接!

如何将我的代码连接到我的 GUI?

额外信息:Xcode 5.1

4

1 回答 1

3

您必须声明插座,然后在 xib 中连接插座。ctrl-drag(或单击鼠标右键并拖动)从 AppDelegate 到文本字段。然后从按钮 ctrl 拖动到 AppDelegate 并选择要发送的方法。

    -- 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_
于 2014-05-29T14:39:06.283 回答