0

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

4

2 回答 2

0

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

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

  1. 文档的一类
  2. NSWindowController 的一个子类来控制视图

这遵循 MVC 架构:

  • 型号:文档
  • 控制器:附在窗口上
  • 视图:窗户

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

于 2011-05-27T07:24:38.497 回答
0

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

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

  • 打开笔尖文件。
  • 转到菜单并导航到应该触发操作的“运行”菜单项。
  • Ctrl-单击菜单项并将连接线拖动到窗口控制器。
  • 当您释放拖动时,您应该会看到一个菜单弹出。单击launchSim:您应该一切就绪。
于 2011-05-25T20:31:17.740 回答