删除/插入视图后,NSResponder 链被破坏

编程入门 行业动态 更新时间:2024-10-27 13:28:45
本文介绍了删除/插入视图后,NSResponder 链被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

看来,当我从 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 18:04:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/919120.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   NSResponder

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!