【问题标题】:How to program radio buttons in Cocoa Applescript (ApplescriptObjC)如何在 Cocoa Applescript (ApplescriptObjC) 中对单选按钮进行编程
【发布时间】:2014-07-22 15:24:57
【问题描述】:

所以现在我已经在 Xcode 上构建了一个用户界面,并且正在编写 AppleScriptObjC 脚本。

我的界面上有 4 个单选按钮。我如何对它们进行编程?这是我当前的代码:

-- IBOutlets
property window : missing value
property question1Radio1 : missing value
property question1Radio2 : missing value
property question1Radio3 : missing value
property question1Radio4 : missing value
property enterButton : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

--Radio button script here

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits 
    return current application's NSTerminateNow
end applicationShouldTerminate_

这是我刚刚尝试但不起作用的代码

    -- IBOutlets
property window : missing value
property question1Radio1 : missing value
property question1Radio2 : missing value
property question1Radio3 : missing value
property question1Radio4 : missing value
property enterButton : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

on buttonClicked_(sender)

    if question1Radio1 = false as boolean then display alert "Works"

end buttonClicked_

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits

    return current application's NSTerminateNow
end applicationShouldTerminate_

【问题讨论】:

    标签: xcode radio-button applescript radio applescript-objc


    【解决方案1】:

    我建议整个矩阵只使用一个插座,而不是 4 个单独的按钮。然后,您可以连接矩阵,并在按钮(或矩阵,如果你喜欢)的发送动作中,获取矩阵的索引以对其进行操作。 如:

    on buttonWasClicked_(sender)        
        set theCol to (questionMatrix's selectedColumn()) as integer
        set theRow to (questionMatrix's selectedRow()) as integer
    
        if {theCol, theRow} is {0,0} then 
        -- do stuff
        else if …
    

    你的问题很笼统。我不知道你在这个过程中做了哪些部分,不知道。因此,请继续在 cmets 中澄清或修改您的问题,以便我们提供您需要的内容。

    【讨论】:

    • 我目前正在尝试在我正在进行的测验中使用单选按钮。
    • 那么这个语法应该可以适应你的需要。询问您是否有任何问题。
    • 你能告诉我这个脚本的含义吗?我做 applescript 大约 6 个月,而 AppleScriptObjC 只做了一周。
    • 我会这样做的。但是,如果您发布界面的屏幕截图,我可能会提供更好的帮助。
    • 我正在尝试获取单选按钮点亮和未点亮时的值。就像,当没有点亮时,我得到了错误。当它被点亮时,我就明白了。问题上的新代码是我刚刚尝试但不起作用的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2011-07-16
    • 2011-11-01
    • 2013-06-14
    • 2013-01-25
    • 2013-06-02
    相关资源
    最近更新 更多