是否有一种智能方法来处理 NSScrollView 中的视图交换/重用?
背景:
我正在 Cocoa/Objective-C 中构建一个基于视图的 NSTableView 式控件,它在能够在 Interface Builder 中布局视图方面提供了 UITableView 的易用性,而不是而不是尝试子类化 NSCell。它的资源也很智能,因为它采用了类似 UITableView 的可重用单元范式。当然,这一切都是在 NSScrollView 内部完成的。
我已经解决了大部分棘手的视图交换问题,并且正在工作。滚动时,如果视图被完全裁剪,则会将其添加到未使用视图池中。类似地,如果未显示的视图进入可视区域,它会尝试从未使用的池中获取视图,如果没有可用的视图,它会从保存视图原型的笔尖创建一个新视图。
类似的解决方案确实存在,但我喜欢修补并且喜欢自己实现它:)。但是,我不知道处理此问题的解决方案,我需要一些建议!
问题:
例如,每个视图都包含一个文本字段。如果正在编辑文本字段,并且用户开始滚动,我希望该单元格不被释放到池中,这样它就不会“失去焦点”,或“将焦点赋予”新显示的视图重用已发布的版本。是否有一种智能方法可以将视图标记为正在编辑,而不需要创建自定义视图的程序员拦截事件并将其标记为此类?
感谢您的帮助!
Background:
I'm building a view-based NSTableView-esque control in Cocoa/Objective-C that offers the ease of use of a UITableView in terms of being able to layout a view in Interface Builder, rather than attempting to subclass NSCell. Its also smart with its resources, in that it adopts a similar reusable cell paradigm like UITableView. This is, of course, all done inside of an NSScrollView.
I've got most of the tricky view swapping figured out, and working. When scrolling, if a view is completely clipped, it is added to a pool of unused views. Similarly, if an undisplayed view comes into the viewable area, it attempts to grab a view from the unused pool, and if none are available, it creates a new one from the nib holding the view prototype.
Similar solutions out there do exist, but I like tinkering around and am enjoying implementing it myself :) . However, I don't know of a solution that handles this issue, and I need some advice!
The issue:
Say, for example, that each view contains a text field. If the text field is being edited, and the user begins to scroll, I'd like for that cell to not be released into the pool so that it doesn't "lose focus", or "give focus" to a newly displayed view that reuses the released one. Is there an intelligent way to mark a view as being edited without requiring the programmer who created the custom view to intercept events, and mark it as such?
Thank you for the assistance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的视图控制器可以符合
NSEditorRegistration
非正式协议。它正是为了解决这个问题而设计的。Your view controller could conform to the
NSEditorRegistration
informal protocol. It is designed to handle exactly this issue.