NSProgressBar startAnimation 从 ManiMenu 操作调用

发布于 2024-11-09 19:49:04 字数 1129 浏览 4 评论 0原文

StackOverflow 和 Cocoa newbye 中的第一个问题,另外我正在使用 XCode 4(所以请友善!)

场景:

一个简单的 NSPersistentDocument 多窗口:每个文档都有一个 window.nib< /strong> 和附加的 WindowController 当我按下WINDOW TOOLBAR中的按钮时,应用程序运行NSTask(在后台)。

在窗口(视图内)中,我决定放置一个漂亮的 NSProgressIndicator (不确定),它在任务开始时动画,在任务结束时停止动画(我通过通知收集任务消息)。

示例代码:

NSButton --> IBA动作 --> WindowController 中的方法

- (IBAction)launchSim:(id)sender 
{
[simcell launchTask];
[progBar startAnimation:self];
   .... more code ...
}

一切都运行良好且完美。

现在(像往常一样,在这种情况下)你会遇到一个奇怪的错误,并且开始变得效率低下:

我决定也从 MainMenu(从 NSMenuItem)运行相同的操作:

在 MainMenu.xib 中:

NSMenuItem(“RUN”)- ->第一响应者 -->第一响应者中的用户定义操作:launchSim(类型 id)

RUN 菜单项正确运行任务(我有 NSLog DEBUG 消息),但进度条的动画(startAnimation)未启动!

两个操作的区别:

  • 第一个操作(工作)是从 WindowController 拥有的 Nib 文件中调用的,
  • 第二个操作(不工作)是从 MainMenu.xib 中调用的,并发送到 FirstResponder

这两个操作都正确执行了其他部分方法中的代码,但如果我从菜单调用该操作,我看不到进度指示器的任何动画。

我缺少什么?

谢谢并致以最诚挚的问候

First question in StackOverflow and also Cocoa newbye and in addition I am using XCode 4 (so be kind please!)

Scenario:

A simple NSPersistentDocument Multi-windows: each document have a window.nib and an attached WindowController
The application RUN a NSTask (in background) when I press a button in the WINDOW TOOLBAR.

In the window (inside a View) I decided to put a nice NSProgressIndicator (indeterminate) that animate when task start and stopAnimation when task end (I collect task messages trough Notifications).

Sample Code:

NSButton --> IBAction --> method in the WindowController

- (IBAction)launchSim:(id)sender 
{
[simcell launchTask];
[progBar startAnimation:self];
   .... more code ...
}

Everything works nice and perfectly.

Now (as usual in this scenarios) you get a strange bug and you start to become unproductive:

I decide to run the same Action also from the MainMenu (from an NSMenuItem):

In the MainMenu.xib:

NSMenuItem ("RUN") --> FirstResponder --> User Defined Action in First responder:launchSim (type id)

The RUN menu item run correctly the Task (I have NSLog DEBUG messages) BUT the animation (startAnimation) of the progressBar don't start!

THe DIFFERENCE in the 2 Actions:

  • the first one (working) is called from the Nib file owned by the WindowController
  • the second one (not working) is called from the MainMenu.xib and sent to FirstResponder

Both the actions execute correctly the other part of code in the method, but if I call the action from the menu I can't see any animation of the progress indicator.

What I missing?

Thanks and Best Regards

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

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

发布评论

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

评论(2

末骤雨初歇 2024-11-16 19:49:04

您无需对第一响应者执行任何操作即可将菜单项连接到操作。

使菜单项执行操作的方式与使按钮执行操作的方式完全相同:

  • 打开 nib 文件。
  • 转到菜单并导航到应该触发该操作的“运行”菜单项。
  • 按住 Ctrl 键单击菜单项并将连接线拖动到窗口控制器。
  • 当您释放拖动时,您应该会看到弹出一个菜单。单击 launchSim:,您应该已准备就绪。

You don't need to do anything with a first responder in order to connect a menu item to an action.

Making a menu item perform an action works exactly the same way as making a button perform an action:

  • Open the nib file.
  • Go to the menu and navigate to your "Run" menu item that is supposed to trigger the action.
  • Ctrl-Click on the menu item and drag the connecting line to the window controller.
  • When you release the drag, you should see a menu pop up. Click launchSim: and you should be all set.
深爱成瘾 2024-11-16 19:49:04

好吧,我对自己回答,因为我发现了错误:

该结构是“高级”NSPersistentDocument 的经典结构:

  1. 一个用于文档的类,
  2. 一个 NSWindowController 的子类,用于控制

遵循 MVC 架构的视图:

  • 模型:文档
  • 控制器:附加到窗口
  • 视图:窗口

我的错误是在视图中创建一个 NSObject 并将其链接到 NSWindowController,而正确的方法是将 NSWindowController 的子类设置为 File所有者,现在神奇的是,主菜单也开始动画。这在某种程度上与响应者链有关,但与我目前对 Cocoa 的了解相去甚远。如果有人可以发表评论并解释一下......

Well I answer to myself cause I find the bug:

The structure is the classic structure for an "advanced" NSPersistentDocument:

  1. one class for the document
  2. one subclass of the NSWindowController to control the view

this follow the MVC architecture:

  • Model: the document
  • Controller:attached to the window
  • View: the window

My mistake was to CREATE an NSObject in the view and link him to the NSWindowController, while the correct way to do this is to SET you SubClass of the NSWindowController as File Owner and now magically, also the MainMenu start the animation. This is somehow related to the chain of responders but is far away from my current knowledge of Cocoa. If anyone can comment and explain....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文