Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 调用addObject后,NSArrayController选择的索引更改为0 我的设置:_Objective C_Macos_Nstableview_Cocoa Bindings_Nsarraycontroller - Fatal编程技术网

Objective c 调用addObject后,NSArrayController选择的索引更改为0 我的设置:

Objective c 调用addObject后,NSArrayController选择的索引更改为0 我的设置:,objective-c,macos,nstableview,cocoa-bindings,nsarraycontroller,Objective C,Macos,Nstableview,Cocoa Bindings,Nsarraycontroller,我正在制作一个基于选项卡的应用程序,使用NSTableView显示选项卡并允许用户选择选项卡 我将NSTableView绑定到NSArrayController(tableView.content绑定到arrayController.arrangedObjects,tableView.SelectionIndex绑定到arrayController.SelectionIndex) 我的arrayController内容已绑定到我的ViewController中的NSMutableArray

我正在制作一个基于选项卡的应用程序,使用NSTableView显示选项卡并允许用户选择选项卡

我将NSTableView绑定到NSArrayController(tableView.content绑定到arrayController.arrangedObjects,tableView.SelectionIndex绑定到arrayController.SelectionIndex)

我的arrayController内容已绑定到我的ViewController中的NSMutableArray

My arrayController未设置为选择插入的对象(请参见屏幕截图)

我的问题是: 每当我调用[myArrayController addObject:]时,selectedIndex会变回0(即使我选中了“保留选择”)。我不想要这种行为。添加或删除对象后,我希望所选内容保持在同一选项卡上


以前有人遇到过这种情况吗?

取消选择“避免空选择”为我修复了一个类似的问题(我的第一个插入对象是自动选择的)。NSArrayController将保留一个选择,除非数组中没有对象,这似乎不会影响现有选择,但值得一试。

我注意到您正在将arrayController的selection Indexes属性绑定到文件所有者名为
selectedIndex
的属性。NSArrayController的Selection Indexes属性是NSIndexSet,而不是NSUInteger。我很容易想象这样的不匹配会在您看到的问题中表现出来。遗憾的是,selectedIndex属性实际上是文件所有者中的NSIndexSet,尽管我同意,但我可能会重命名它以避免混淆。