从其他类访问IBOutlet

从其他类访问IBOutlet

本文介绍了从其他类访问IBOutlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于文档的可可应用程序,其中一个项目在应用程序菜单中连接到 IBAction 。单击项目需要执行在主要nib文件中使用 IBOutlet 的任务,该文件使用另一个类 MyDocument 。创建同一类的2个对象,每个笔尖中有一个似乎不工作。

I have a document based cocoa application with an item in the application menu hooked up to an IBAction. Clicking the item needs to perform a task that uses an IBOutlet in the main nib file which is using another class, MyDocument. Creating 2 objects of the same class, one in each nib seems to not be working. How can I access the outlet?

推荐答案

菜单项的操作通常发送到第一个响应者,

Actions for menu items are often sent to the first responder so that whatever is currently selected can act on it.

听起来这个动作是对当前文档有效的,然后它应该由文档实现。在这种情况下,菜单将其操作发送给第一个响应者,然后将Action方法放在MyDocument类中。

It sounds like this action is something that works on the current document, then it should be implemented by the document. In this case have the menu send it's action to the first responder and then put the action method in the MyDocument class.

如果您尝试发送的操作是自定义一个:在主菜单nib中选择First Responder项,添加您的方法名,然后将菜单项的选择器连接到操作。

If the action you are trying to send is a custom one: in the Main Menu nib select the First Responder item, add your method name, then connect the menu item's selector to the action.

读取部分了解更多信息。

Read the Responders section of the Cocoa Event-Handling Guide for more info.

这篇关于从其他类访问IBOutlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:39