使用 NSViewController 加载笔尖后...如何访问笔尖中的 NSButton?
我已经将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如互动小说解释者所说,“这似乎缺少一个动词。”
您有一个接收器 (
viewController
)、一个完整的消息表达式 ([toDoButton setTitle:…]
) 和括号,但缺少一个选择器。因此,这不是有效的消息表达式。有两种可能性:
setTitle:
的结果作为其参数传递,但您忘记了选择器。我发现这不太可能,因为 NSButton 的setTitle:
不返回任何内容。setTitle:
消息。假设此视图控制器是 NSViewController 子类的实例,您已在其中添加了toDoButton
属性,请使用[[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:
setTitle:
as its argument, and you forgot the selector. I find this unlikely, because NSButton'ssetTitle:
doesn't return anything.setTitle:
message. Assuming that this view controller is an instance of a subclass of NSViewController in which you've added atoDoButton
property, use either[[viewController toDoButton] setTitle:someStringHere]
or[viewController.toDoButton setTitle:someStringHere]
.