NSProgressBar startAnimation 从 ManiMenu 操作调用
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无需对第一响应者执行任何操作即可将菜单项连接到操作。
使菜单项执行操作的方式与使按钮执行操作的方式完全相同:
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:
好吧,我对自己回答,因为我发现了错误:
该结构是“高级”NSPersistentDocument 的经典结构:
遵循 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:
this follow the MVC architecture:
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....