给我的程序“选项”

发布于 2024-10-27 08:05:58 字数 445 浏览 5 评论 0原文

在 XCode 4 中我创建了 3 个小程序:一个计算器、一个“便签本”(空白笔记型窗口)和“电子表格”(看起来像电子表格,用于保存通过计算器获得的值)

好的 我现在想做的就是在计算器中添加一个按钮,按下该按钮时,将执行便笺本或电子表格,并让用户选择选择哪一个。

我已将这两个包放在“应用程序”文件夹中,以便很容易找到它们。

我想知道是否需要子类化 NSButton 或者是否有更简单的方法来实现。

我想我可以让 NSButton 在 /users/me/applications 打开一个文件浏览器,然后当用户(我:-))选择其中一个应用程序时,它只会将其存储为按钮将要使用的变量然后当我按下它的等效键时执行。

但是我不知道如何为按钮提供两种不同的操作,“单击”和“按下”

如果我必须对按钮进行子类化,我应该从哪里开始寻找?如果有更简单的方法,那会在哪里呢?

Ok,

In XCode 4 I have created 3 small programs: A calculator, a 'scratch pad' (blank note-type window), and 'spread sheet' (just looks like a spread sheet, for holding values gained with the calculator)

What I'm trying to do now is add a button to my calculator that will, when pressed, execute either the scratch pad or the spread sheet and give the user the option of which one to pick.

I've placed both the bundles in the 'applications' folder so they are easy to find.

I was wondering if I need to subclass an NSButton or if there is an easier way to do it.

I was thinking that I could just make the NSButton open a file-browser at /users/me/applications and then when the user (me :-) ) chooses one of the applications it will just store it as a variable that the button will then execute when I press it's key-equivalent.

But then I don't know how to give the button two different actions, a 'click' and a 'press'

If I have to subclass the button, where should I begin looking? And if there's an easier way, where would that be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2024-11-03 08:05:58

似乎简单的解决方案是两个按钮,每个程序一个。

如果您打算只使用一个按钮,那么最简单的事情就是让按钮的操作显示一个工作表或对话框,让用户决定启动哪个应用程序。

Seems like the simple solution would be two buttons, one for each program.

If you're set on using just one button, then the straightforward thing to do is to have the button's action display a sheet or dialog box that lets the user decide which application to launch.

情绪 2024-11-03 08:05:58

我喜欢这种方法,听起来不错。有什么方法可以让菜单允许我决定按钮将运行哪个程序,然后按下其“键盘等效项”将实际启动该程序? –TotalCocoaNewb

当然是这样:

-(IBAction)theActionYouSetOnThePopupButtonInInterfaceBuilder:(NSPopUpButton*)sender
{
    if ( 0 == [sender indexOfSelectedItem] ) {
       // do something...
    } else {
       // do something else...
    }
}

I like this approach, it sounds nice. Is there any way to make it so that the menu allows me to decide which of the programs the button will run, and then pressing its 'keyboard equivalent' will actually launch the program? – TotalCocoaNewb

Certainly so:

-(IBAction)theActionYouSetOnThePopupButtonInInterfaceBuilder:(NSPopUpButton*)sender
{
    if ( 0 == [sender indexOfSelectedItem] ) {
       // do something...
    } else {
       // do something else...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文