现在我想使列中的文本字段可编辑.
我的第一次尝试是从Interface构建器修改NSTextFIEld并将其行为设置为Editable.它确实有效,当我选择一行并按下回车键时,该字段变得可编辑,我可以更改其值.我想我可以通过一些NStableVIEwDataSource方法拦截这个更改,例如tableVIEw:setobjectValue:fortableColumn:row:但是这个方法永远不会被调用以响应文本字段编辑 *** 作.
在基于视图的NStableVIEw系统中处理可编辑字段的正确方法是什么?我想NStableVIEwDataSource与它有关,但我不知道如何调用它的方法.
解决方法 创建NStableCellVIEw的子类. (适当的.h和.m文件)使类响应NSTextFIEldDelegate协议.实现控件:textShouldEndEditing:方法.使此子类成为标签控件的委托.这是一些示例代码.
categoryListCell.h
@interface categoryListCell : NStableCellVIEw@end
categoryListCell.m
@interface categoryListCell()<NSTextFIEldDelegate>@property (weak) IBOutlet NSTextFIEld *categoryLabel;@property (assign) BOol editing;@property (copy) Nsstring* category;@end@implementation categoryListCell- (BOol)control:(NSControl*)control textShouldBeginEditing:(NSText *)fIEldEditor { self.editing = YES; return YES;}- (BOol)control:(NSControl *)control textShouldEndEditing:(NSText *)fIEldEditor; { if (self.editing) { self.editing = NO; [self mergeFromSource:self.category toDestination:self.categoryLabel.stringValue]; } return YES;}- (voID)mergeFromSource:(Nsstring*)source toDestination:(Nsstring*) destination { // your work here}@end总结
以上是内存溢出为你收集整理的macos – 使NSTableCellView可编辑全部内容,希望文章能够帮你解决macos – 使NSTableCellView可编辑所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)