gpt4 book ai didi

cocoa - NSOutlineView 中 rowForView 和 selectRowIndexes 的奇怪行为

转载 作者:行者123 更新时间:2023-12-03 17:52:35 31 4
gpt4 key购买 nike

我的应用程序中有一个源 ListView ,该 View 设置为基于 View 。然后,我通过此方法向我的单元格添加了一个徽章/按钮;

First subclass NSTableCellView, add an IBOutlet for an NSButton and a @synthesize/@property statement to it. Then open the NSTableCellView that should have a badge in Interface Builder. Set it's class to your newly created subclass and add a button to it. Set the button style to "inline" and it's type to "switch".

Now select the NSTableCellView again and connect the NSButton IBOutlet to your added button. That's it. You can now call e.g. [[cellView button] setTitle@"123"]] to set the rows badge label to 123 or any arbitrary string.

这效果很好,但单击徽章实际上并没有选择该行,因此我向按钮添加了一个单击处理程序。

- (IBAction)sourceListBadgeClicked:(id)sender {
NSUInteger selectedRow = [self.outlineView rowForView:sender];
if (selectedRow == -1) {
return;
}

NSLog(@"click row: %lu", selectedRow);

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:1];
[self.outlineView selectRowIndexes:indexSet byExtendingSelection:NO];
}

我可以看到处理程序被调用,但 selectedRow 始终返回为 0,并且 selectRowIndexes 实际上并未选择该行(我硬编码为 1 只是为了测试)..是否有什么我遗漏的来做到这一点?

最佳答案

事实证明,为您尝试操作的 View 绑定(bind) IBOutlet 确实很有帮助。我的菜鸟错误。

关于cocoa - NSOutlineView 中 rowForView 和 selectRowIndexes 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21761622/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com