- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在以编程方式制作几个按钮并尝试为每个按钮设置一个 Action ,但我似乎无法让它工作。
在我的 AppController.h 中我有这段代码:
...
IBOutlet NSButton* btnZoomIn;
IBOutlet NSButton* btnZoomOut;
...
和
- (IBAction) zoomIn : (id) sender;
- (IBAction) zoomOut : (id) sender;
在 AppController.m 中的 awakeFromNib 方法中:
/*zoom in and out buttons*/
//get the path to the image files
NSString* zoomInImgPath = [[NSBundle mainBundle] pathForResource:@"zoomIn" ofType:@"png"];
NSString* zoomOutImgPath = [[NSBundle mainBundle] pathForResource:@"zoomOut" ofType:@"png"];
//declare the NSImages
zoomInImg = [[NSImage alloc] initWithContentsOfFile:zoomInImgPath];
zoomOutImg = [[NSImage alloc] initWithContentsOfFile: zoomOutImgPath];
//button making!
//zoomIn
btnZoomIn = [[NSButton alloc] initWithFrame:NSMakeRect(1426.0, 920.0, 25.0, 25.0)];
[btnZoomIn setButtonType:NSMomentaryPushInButton];
[btnZoomIn setTitle:@""];
[btnZoomIn setToolTip:@"Zoom In"];
[btnZoomIn setImage:zoomInImg];
[btnZoomIn setAction:@selector(zoomIn:)];
[[mainWin contentView] addSubview:btnZoomIn];
//zoomOut
btnZoomOut = [[NSButton alloc] initWithFrame:NSMakeRect(1456.0, 920.0, 25.0, 25.0)];
[btnZoomOut setButtonType:NSMomentaryPushInButton];
[btnZoomOut setTitle:@""];
[btnZoomOut setToolTip:@"Zoom Out"];
[btnZoomOut setImage:zoomOutImg];
[btnZoomOut setAction:@selector(zoomOut:)];
[[mainWin contentView] addSubview:btnZoomOut];
和
- (IBAction) zoomIn : (id) sender {
NSLog(@"zoom in!");
}
- (IBAction) zoomOut : (id) sender {
NSLog(@"zoom out!");
}
但是 zoomOut 和 zoomIn 不会被击中...
最佳答案
最可能的原因是 responder chain for action messages 中没有对象回应这些行动。当您指定一个 Action 但未指定目标时,Cocoa 会尝试通过遍历响应者链来找到响应这些 Action 消息的对象。
要么确保您在响应者链中有合适的对象,要么如果您有对该对象的引用,请将其指定为这些操作的目标:
[btnZoomIn setAction:@selector(zoomIn:)];
[btnZoomIn setTarget:objectThatRespondsToZoomIn];
[btnZoomOut setAction:@selector(zoomOut:)];
[btnZoomOut setTarget:objectThatRespondsToZoomOut];
关于Objective-c:NSButton setAction 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7365625/
我已成功创建 HTTP 基本身份验证客户端。 有一个特定的操作,我对其目的有些怀疑。 我尝试了一个简单的 helloworld 脚本的教程,互联网上还有一些其他教程,我看到了这个: options.s
我被这个问题困扰了 3 天,我做了很多研究,但找不到任何答案,这里是对正在发生的事情的简要解释,尝试使用 Firebase 数据库和使用 Unity3D 进行身份验证,这里是步骤: 第一个用户登录,如
我目前正在实现 Google Analytics 增强型电子商务。当我在我的开发环境中购买东西时,我会检查我的开发分析购物行为,我只看到所有 session 和带有事务的 session 中的值,但两
我只想添加一个带有 setAction 参数的 NSButton。 NSRect frame = NSMakeRect(10, 40, 90, 40); NSButton* pushButton =
当尝试打开 Activity 时,我的应用程序在某些设备中崩溃。该问题并不总是发生,仅在某些设备上发生。 @Override protected void onCreate(Bundle savedI
我的游戏中有一个类似于电源对象的对象:当我的玩家输入电源时,它应该激活一个指示电源已被获取的面板,并在 3 秒后该面板应该消失。目前,当我按下电源时,我的面板出现了,但它并没有消失。我正在使用这样的协
我在 Unity 中隐藏 UI 面板时遇到问题。当客户端连接到服务器时调用代码。 void OnPlayerConnected(NetworkPlayer player) { gameObj
我的理解是,您的应用中只能有 1 个 AVAudioSession(因为它是单例,因此您总是收到相同的实例)。 那么,setActive() 函数的作用是什么?因为我只能有一个 session ,所以
我有一个要为其设置操作的表格。我想使用在 bootstrap 中创建的路由在表单文件(扩展Zend_Form)中而不是在 Controller 或 View 中声明操作。 通常,当我想使用路线时,我会
setAction() 到底做了什么?我发现What does setAction () do for intent (Broadcast)但没理解清楚 public void increme
从 unity 项目中学习滚动一个球项目,当玩家与其发生碰撞时拾取器不会移除。它就像透明物体一样穿过它们内部,这是我的代码。 void onTriggerEnter(Collider other) {
TL/DR: 调用 window.setActive(false) 不会将窗口的 active 属性设置为 false。 完整详细信息: 我有以下继承自 Ext.window.Window 的 Ext
我正尝试在 Android 6.0 或更高版本上将我的应用列入白名单。我已经看到 Android 代码可以执行此操作,但它不会在 Xamarin 中进行翻译,Xamarin 文档仅告诉您 SetAct
以下代码呈现一个没有文本的 JButton: public abstract class Test { public static void main(String... args) {
我正在以编程方式制作几个按钮并尝试为每个按钮设置一个 Action ,但我似乎无法让它工作。 在我的 AppController.h 中我有这段代码: ... IBOutlet NSButton* b
调用 MyAlreadyActiveGameObject.SetActive(true) 是否有任何性能问题?一吨,例如每帧一次? 换句话说,是否值得拉 gameObject.active向上检查?或
我想尝试创建一个简单的 cocoa 应用程序。这是一个简单的 reddit 收件箱通知程序。我引入了一堆 URL,并希望为每个 URL 制作带有页面链接的菜单项。我想动态地设置每个 Action 。我
我正在以编程方式在继承 NSObject 的界面内添加工具栏,并实现这些方法: - (NSToolbarItem*)toolbar:(NSToolbar*)toolbar itemForItemId
我使用以下代码以编程方式创建了 NSPopUpButton [myPopUpButton insertItemWithTitle:@"--Select one--" atIndex:0]; [myPo
在我的 iOS 应用程序中,我首先启动 iPod 中的歌曲,然后启动我的应用程序。我在我的应用程序中按下一个按钮,然后调用 AVAudioSession * audioSession = [AVAud
我是一名优秀的程序员,十分优秀!