删除/插入视图后,NSResponder 链被破坏 [英] NSResponder chain being broken after i remove / insert views

查看:21
本文介绍了删除/插入视图后,NSResponder 链被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,当我从 NSViewController 主视图中删除子视图时,响应者链被修改,新视图永远不会收到第一响应者.

It appears that when i remove subviews from my NSViewController main view, responder chain gets modified and new views never receive the first responder.

视图控制器在弹出框内.顶部有搜索字段,下方有自定义视图(搜索结果).当我显示 popover 时,我可以使用 tab 转到自定义视图.但是,如果我搜索某些短语,搜索结果会发生变化,并且选项卡不再有效.

View controller is inside popover. There is search field on top, and custom views below (search results). When i show popover i can use tab to go to the custom views. But if i search for some phrase search results are changed and tab no longer works.

知道是否有办法修复"响应者链?

Any idea if there is way to 'fix' the responder chain ?

推荐答案

Mike Abdullah 的回答

Answer from Mike Abdullah

NSPopover:关键视图循环

在浏览 NSPopover 时,有一个发现让我有点惊讶:AppKit 在幕后为 popover 创建的 NSWindow 已关闭 autorecalculatesKeyViewLoop.如果您动态更改弹出框的内容或布局,这可能会产生一些奇怪的结果,因为 AppKit 不会考虑这些更改.

While poking around NSPopover, one discovery has slightly surprised me: The NSWindow that AppKit creates behind the scenes for the popover has autorecalculatesKeyViewLoop turned off. That can have slightly odd consequences if you’re dynamically changing the content or layout of the popover, since AppKit won’t take those changes into account.

(如果您需要快速解释,Key View Loop 定义了当您按下 Tab 键时会发生什么,控制焦点移动到哪个位置)

(If you need a quick explanation, The Key View Loop defines what happens when you hit the tab key, which control the focus moves to)

由于我们不拥有有问题的窗口,所以我有点犹豫要不要打开 autorecalculatesKeyViewLoop.相反,在您进行更改后,在窗口上调用 recalculateKeyViewLoop 通常非常简单.

Since we don’t own the window in question, I’m a little hesitant to turn autorecalculatesKeyViewLoop on. Instead, it’s generally pretty simple to call recalculateKeyViewLoop on the window after you’ve made a change.

这篇关于删除/插入视图后,NSResponder 链被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆