gpt4 book ai didi

cocoa - 如何重新绑定(bind) NSTableColumn 的 NSValueBinding?

转载 作者:行者123 更新时间:2023-12-03 17:22:34 25 4
gpt4 key购买 nike

我正在构建一个 Mac OS X 应用程序,该应用程序具有一个带有单个 NSTableColumn 的 NSTableView 和一个 NSSegmentedControl。当我选择不同的段时,我打算切换 TableView 以显示来自不同数组 Controller 的行。

表列最初通过 IB 中的键路径 arrangedObjects.name 绑定(bind)到 self.songsArrayController。当所选段发生如下更改时,我当前正在重新绑定(bind)表列的值绑定(bind):

- (IBAction) segmentedControlChanged:(NSSegmentedControl*) sender {
if (sender.selectedSegment == 0) {
[self.songNameTableColumn bind:NSValueBinding toObject:self.songsArrayController withKeyPath:@"arrangedObjects.name" options:nil];
} else if (sender.selectedSegment == 1) {
[self.songNameTableColumn bind:NSValueBinding toObject:self.productsArrayController withKeyPath:@"arrangedObjects.localizedTitle" options:nil];
}
}

当我单击第二段时,我看到以下错误:

2013-08-16 08:55:26.245 MyApp[76005:303] [<SKProduct 0x10b3264d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.
2013-08-16 08:55:26.270 MyApp[76005:303] (
0 CoreFoundation 0x00007fff96d69b06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8c7ea3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff96dfdf49 -[NSException raise] + 9
3 Foundation 0x00007fff977ac15c -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 238
4 Foundation 0x00007fff976f3ea9 -[NSObject(NSKeyValueCoding) valueForKey:] + 400
5 Foundation 0x00007fff9771474c -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 341
6 Foundation 0x00007fff97714713 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 284
7 AppKit 0x00007fff8dbf70a4 -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] + 163
8 AppKit 0x00007fff8dbf99f7 -[NSValueBinder _adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState:] + 667
9 AppKit 0x00007fff8dbf964c -[NSValueBinder _observeValueForKeyPath:ofObject:context:] + 192
10 AppKit 0x00007fff8dbfe0ab -[NSTextValueBinder _observeValueForKeyPath:ofObject:context:] + 43
11 Foundation 0x00007fff977167b7 NSKeyValueNotifyObserver + 390
12 Foundation 0x00007fff977181c1 NSKeyValueDidChange + 456
13 Foundation 0x00007fff976d376a -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
14 AppKit 0x00007fff8dc3bae6 -[NSTableRowData _addViewToRowView:atColumn:row:] + 696
15 AppKit 0x00007fff8dc3b63f -[NSTableRowData _addViewsToRowView:atRow:] + 151
16 AppKit 0x00007fff8dc39bd5 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 415
17 AppKit 0x00007fff8dc3995a -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 272
18 AppKit 0x00007fff8dc38c29 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 740
19 AppKit 0x00007fff8dc387c1 -[NSTableRowData updateVisibleRowViews] + 119
20 AppKit 0x00007fff8dc105a7 -[NSTableView layout] + 165
21 AppKit 0x00007fff8dbc3e65 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 112
22 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
23 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
24 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
25 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
26 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
27 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
28 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
29 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
30 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
31 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
32 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
33 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
34 CoreFoundation 0x00007fff96d624a6 __NSArrayEnumerate + 582
35 AppKit 0x00007fff8dbc3fc6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
36 AppKit 0x00007fff8dbc3cfe -[NSView layoutSubtreeIfNeeded] + 615
37 AppKit 0x00007fff8dbbf4ac -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 201
38 AppKit 0x00007fff8dab90a8 _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 446
39 Foundation 0x00007fff976fe463 __NSFireTimer + 96
40 CoreFoundation 0x00007fff96d26804 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
41 CoreFoundation 0x00007fff96d2631d __CFRunLoopDoTimer + 557
42 CoreFoundation 0x00007fff96d0bad9 __CFRunLoopRun + 1529
43 CoreFoundation 0x00007fff96d0b0e2 CFRunLoopRunSpecific + 290
44 HIToolbox 0x00007fff8f1c2eb4 RunCurrentEventLoopInMode + 209
45 HIToolbox 0x00007fff8f1c2c52 ReceiveNextEventCommon + 356
46 HIToolbox 0x00007fff8f1c2ae3 BlockUntilNextEventMatchingListInMode + 62
47 AppKit 0x00007fff8dab6533 _DPSNextEvent + 685
48 AppKit 0x00007fff8dab5df2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
49 AppKit 0x00007fff8daad1a3 -[NSApplication run] + 517
50 AppKit 0x00007fff8da51bd6 NSApplicationMain + 869
51 MyApp 0x0000000100001fc2 main + 34
52 libdyld.dylib 0x00007fff97d227e1 start + 0
)

看来,即使我使用键路径 arrangedObjects.localizedTitle 将 NSValueBinding 重新绑定(bind)到 self.productsArrayController,表列仍在尝试使用arrangedObjects.name 的旧键路径。有谁知道为什么会发生这种情况,以及如何正确地将现有 NSTableColumn 重新绑定(bind)到不同的数组 Controller 和键路径?

最佳答案

在设置新绑定(bind)之前尝试调用 -unbind::

- (IBAction) segmentedControlChanged:(NSSegmentedControl*) sender {
if (sender.selectedSegment == 0) {
[self.songNameTableColumn unbind:NSValueBinding];
[self.songNameTableColumn bind:NSValueBinding toObject:self.songsArrayController withKeyPath:@"arrangedObjects.name" options:nil];
} else if (sender.selectedSegment == 1) {
[self.songNameTableColumn unbind:NSValueBinding];
[self.songNameTableColumn bind:NSValueBinding toObject:self.productsArrayController withKeyPath:@"arrangedObjects.localizedTitle" options:nil];
}
}

此外,您是否已验证数组 Controller 都包含它们应该包含的对象。 IE。 productsArrayController 是否包含 SKProductssongsArrayController 是否包含 Song (或任何真正的类)对象?

关于cocoa - 如何重新绑定(bind) NSTableColumn 的 NSValueBinding?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18277718/

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