- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以通过双击列标题来更改 NSTableView 列的名称?有关最佳方法的任何建议。
我正在尝试:
editWithFrame:inView:editor:delegate:event:
来编辑 NSTableHeaderCell 实例。我不完全确定为什么这会扭曲文本,但是当您双击标题时,它会使文本看起来像这样,没有出现字段编辑器,
在 AppDelegate 中,
-(void)awakeFromNib
{
...
[_tableView setDoubleAction:@selector(doubleClickInTableView:)];
...
}
-(void) doubleClickInTableView:(id)sender
{
NSInteger row = [_tableView clickedRow];
NSInteger column = [_tableView clickedColumn];
if(row == -1){
/* Want to edit the column header on double-click */
NSTableColumn *tableColumn = [[_tableView tableColumns] objectAtIndex:column];
NSTableHeaderView *headerView = [_tableView headerView];
NSTableHeaderCell *headerCell = [tableColumn headerCell];
NSRect cellFrame = [headerView headerRectOfColumn:column];
NSText * fieldEditor = [[headerView window] fieldEditor:YES forObject:nil];
[headerCell editWithFrame:cellFrame inView:headerView editor:fieldEditor delegate:headerCell event:nil];
}
}
最佳答案
看来是可行的
您在屏幕截图中看到的是窗口的字段编辑器覆盖单元格的文本字段
编辑器有一个透明的背景,所以这就是它困惑的原因
所以这是交易:
您需要拥有自己的 NSTableHeaderCell 子类来充当字段编辑器的委托(delegate):
@interface NBETableHeaderCell () <NSTextViewDelegate>
@end
@implementation NBETableHeaderCell
- (void)textDidEndEditing:(NSNotification *)notification
{
NSTextView *editor = notification.object;
// Update the title, kill the focus ring, end editing
[self setTitle:editor.string];
[self setHighlighted:NO];
[self endEditing:editor];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
if([self isHighlighted])
{
[self drawFocusRingMaskWithFrame:cellFrame inView:controlView.superview];
}
[super drawWithFrame:cellFrame inView:controlView];
}
- (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
[controlView lockFocus];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect:cellFrame] fill];
[controlView unlockFocus];
}
@end
在应用程序委托(delegate)的 awakeFromNib 中,不要忘记将 NSTableHeaderCell 设置为可编辑!
- (void)awakeFromNib
{
NSTableColumn *newCol = [[NSTableColumn alloc] initWithIdentifier:@"whatever"];
NBETableHeaderCell *hc = [[NBETableHeaderCell alloc] initTextCell:@"Default header text"];
[hc setEditable:YES];
[hc setUsesSingleLineMode:YES];
[hc setScrollable:NO];
[hc setLineBreakMode:NSLineBreakByTruncatingTail];
[newCol setHeaderCell:hc];
[self.tableView addTableColumn:newCol];
[self.tableView setDoubleAction:@selector(doubleClickInTableView:)];
}
剩下的,你就快到了
调用 selectWithFrame 之后,我们将编辑器自定义为具有漂亮的白色不透明背景,
这样我们就看不到它下面的 TextView
至于聚焦环:这是细胞的工作,
我们只是将单元格设置为突出显示状态,这样它就知道现在必须绘制圆环
- (void)doubleClickInTableView:(id)sender
{
NSInteger row = [_tableView clickedRow];
NSInteger column = [_tableView clickedColumn];
if(row == -1&& column >= 0)
{
NSTableColumn *tableColumn = [[_tableView tableColumns] objectAtIndex:column];
NSTableHeaderView *headerView = [_tableView headerView];
NBETableHeaderCell *headerCell = [tableColumn headerCell];
// cellEditor is basically a unique NSTextView shared by the window
// that adjusts its style to the field calling him
// it stands above the text field's view giving the illusion that you are editing it
// and if it has no background you will see the editor's NSTextView overlaying the TextField
// wich is why you have that nasty bold text effect in your screenshot
id cellEditor = [self.window fieldEditor:YES forObject:self.tableView];
[headerCell setHighlighted:YES];
[headerCell selectWithFrame:[headerView headerRectOfColumn:column]
inView:headerView
editor:cellEditor
delegate:headerCell
start:0
length:headerCell.stringValue.length];
[cellEditor setBackgroundColor:[NSColor whiteColor]];
[cellEditor setDrawsBackground:YES];
}
}
有关字段编辑器的更多信息:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/WinPanel/Tasks/UsingWindowFieldEditor.html
现在唯一缺少的事情是,如果您在编辑时调整单元格大小,字段编辑器的框架将不会更新......
关于cocoa - 双击编辑 NSTableView 列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14627631/
非常基本的场景: 我的 Nib 上有一个 NSTableView,有一个指向它的 socket 。我的应用程序委托(delegate)中有以下内容: - (void)applicationDidFin
目前,当我从 NSTableView 中拖出一行时,它是该行中的半透明文本。相反,我想显示代表这一行的半透明图像。 我怎样才能做到这一点? 最佳答案 我建议覆盖 -[NSTableView dragI
我正在使用 NSTableView 来显示我的数据。我想删除默认情况下采用蓝色的选定行的颜色。我可以将其设置为透明颜色吗?可能吗? 编辑: 如何去掉这个蓝色边框?我已将Clear color 设置为表
我正在尝试在 NSTableView 内显示 NSTableView。这是一个类似 iTunes 的专辑/轨道 View 。所以有一个包含 10 张专辑的列表,每个专辑都有一些轨道。我想在外部表格 V
我有一个基于 View 的 NSTableView,其内容绑定(bind)到数组 Controller 。我使用 objectValue.title 绑定(bind)一个特定的文本字段。这工作正常。我
具有单列的基于 View 的 NSTableView。每个“单元格”包含多个 NSTextField、一个 NSImageView 和一个 NSButton,所有这些都绑定(bind)到表格单元格 V
如果我的理解没有错的话,cell-based NSTableView 和 view-based NSTableView 是同一类型的实例。那么,cpu是如何区分cell-based和view-base
我在 10.8 上运行基于 View 的 NSTableView 时遇到问题(目标是 10.7,但我认为这不相关)。 我正在使用 NSTableView,并通过绑定(bind)获取自定义 NSTabl
我有一个有 4 列的 NSTableView。我还为每一行设置了自定义背景颜色。唯一的问题是我有这些丑陋的空白区域,网格线会同时出现在水平轴和垂直轴上。我在 IB 中都取消了检查,但它们仍然出现。如何
我有一个基于 View 的 NSTableView,每一行都必须生成一些需要时间的图像。这些是在后台 NSoperationQueue 上完成的,并在请求图像时启动(通过绑定(bind))。 当一行滚
我的NSTableCellView是子类,并存储指向对象的指针。我想访问该指针,而我唯一获得的信息就是row编号为NSInteger。 如何使用给定的NSTableCellView从我的tableVi
我需要创建一个包含 3 列的 NSTableView,这些列必须适合像这样的空间 20% 60% 20%。我在界面生成器中设置了约束但没有成功。结果总是一样的。显示了 3 列,但大小与 IB 中的相同
我已经尝试了其他帖子中建议选项的多种组合,但我似乎无法使用基于单元格的 NSTableView 填充不可编辑的 NSTextFieldCell 来选择单元格而不是行。 我已经尝试过: [[co
我在区分两个 NSTableView 时遇到问题,需要一些帮助。 我尝试过这些方法: 1. - (void)tableViewSelectionDidChange:(NSNotification *)
我将 NSTableView 绑定(bind)到 NSArrayController。由于某种原因,我根本无法对列进行排序。有些列甚至不显示排序方向箭头。有些确实显示了它,但单击它只是切换箭头方向,它
我在 TableView 中第一行的索引是“0”,这是正确的吗? 如果是,我怎样才能使 TableView 中第一行的索引变为“1”? 这是需要的,因为我的 DataSourse 从“1”开始,我需要
我编写了一个向 NSTableView 添加新行的方法。它添加了新行,但有空,没有文本。代码如下: AppDelegate.h #import @interface AppDelegate : NS
建立委托(delegate)和数据源连接后,我有以下 Controller : #import @interface KextTable : NSObject { @private NSA
我在基于 View 的 NSTableView 中对 NSTableRowView 进行了子类化,以将选择颜色更改为浅蓝色,而不是默认颜色。 不幸的是,当我选择该行时,自定义单元格内的标签和文本字段的
我有一个包含 3 个单元格的 NSTableView。我已经使用以下代码调整了该表格 View 以显示分隔符: [self.tableView setGridColor:[NSColor ligh
我是一名优秀的程序员,十分优秀!