使用 NSViewController 加载笔尖后...如何访问笔尖中的 NSButton?

发布于 2024-08-13 06:54:14 字数 719 浏览 7 评论 0原文

我已经将 NSViewController 子类化,并将 IBOutlets 挂接到辅助笔尖中的 NSButton 中。

我可以实例化 NSViewController 并在 NSMenu 中应用视图——效果很好——但是如何访问按钮来更改其标题?

由于 NSViewController 有 IBOutlets,我假设我会通过控制器来完成此操作。

//this part works great
NSViewController *viewController = [[toDoViewController alloc] initWithNibName:@"toDoView" bundle:nil];
NSView *newView = [viewController view];
newMenuItem.view = newView;

//this part not so much
[viewController [toDoButton setTitle:someStringHere]];

有关于从这里去哪里的指示吗?

编辑添加: toDoViewController 类 --

@interface toDoViewController : NSViewController {
    IBOutlet NSButton *checkBoxButton;
    IBOutlet NSButton *toDoButton;
}

@end

I've subclassed NSViewController with IBOutlets hooked into an NSButton in a secondary nib.

I can instantiate the NSViewController and apply the view in an NSMenu -- it works great -- but how do I access the button to change its title?

Since the NSViewController has IBOutlets, I assumed I'd do this through the controller.

//this part works great
NSViewController *viewController = [[toDoViewController alloc] initWithNibName:@"toDoView" bundle:nil];
NSView *newView = [viewController view];
newMenuItem.view = newView;

//this part not so much
[viewController [toDoButton setTitle:someStringHere]];

Any pointers on where to go from here?

Edit to add: the toDoViewController class --

@interface toDoViewController : NSViewController {
    IBOutlet NSButton *checkBoxButton;
    IBOutlet NSButton *toDoButton;
}

@end

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

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

发布评论

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

评论(1

初见终念 2024-08-20 06:54:14
[viewController [toDoButton setTitle:someStringHere]];

正如互动小说解释者所说,“这似乎缺少一个动词。”

您有一个接收器 (viewController)、一个完整的消息表达式 ([toDoButton setTitle:…]) 和括号,但缺少一个选择器。因此,这不是有效的消息表达式。

有两种可能性:

  1. 您打算向视图控制器发送消息,并将 setTitle: 的结果作为其参数传递,但您忘记了选择器。我发现这不太可能,因为 NSButton 的 setTitle: 不返回任何内容。
  2. 您的意思是从视图控制器获取按钮,然后向按钮发送 setTitle: 消息。假设此视图控制器是 NSViewController 子类的实例,您已在其中添加了 toDoButton 属性,请使用 [[viewController toDoButton] setTitle:someStringHere] 或 <代码> [viewController.toDoButton setTitle:someStringHere] 。
[viewController [toDoButton setTitle:someStringHere]];

As the interactive fiction interpreters would say, “That seems to be missing a verb.”

You have a receiver (viewController), and a complete message-expression ([toDoButton setTitle:…]), and brackets, but you are missing a selector. As such, this isn't a valid message-expression.

There are two possibilities:

  1. You mean to send a message to the view controller, passing the result of setTitle: as its argument, and you forgot the selector. I find this unlikely, because NSButton's setTitle: doesn't return anything.
  2. You mean to get the button from the view controller, then send the button a setTitle: message. Assuming that this view controller is an instance of a subclass of NSViewController in which you've added a toDoButton property, use either [[viewController toDoButton] setTitle:someStringHere] or [viewController.toDoButton setTitle:someStringHere].
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文