Cocoa:禁用视图中所有控件的最佳方法 [英] Cocoa: best way to disable all controls in a view

查看:44
本文介绍了Cocoa:禁用视图中所有控件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 OS X 应用程序中,我在滚动视图中有各种文本字段、按钮和其他控件.有没有办法一次性禁用滚动视图中的元素?

In an OS X app, I have various text fields, buttons, and other controls all inside of a scroll view. Is there a way to disable the elements inside the scroll view all at once?

我想避免在每个项目上调用 setEnabled:,这样如果我以后想向滚动视图添加更多控件,维护起来会更容易.

I'd like to avoid calling setEnabled: on each and every item, so that maintenance is easier if I want to add more controls to the scroll view later on.

我想强调的是,这是针对 OS X 应用程序的,因此适用于 iOS 的技术不一定适用于此.

I'd like to emphasize that this is for an OS X app, so techniques that work in iOS don't necessarily apply here.

推荐答案

您可以遍历内容视图的所有subviews,并调用setEnabled:他们.这可能会通过禁用某些内部视图来破坏滚动视图,因此不要迭代滚动视图本身的 subview 属性.要防止在没有启用属性的视图上调用 setEnabled:,请使用 respondsToSelector:@selector(setEnabled:) 进行检查.

You can iterate through all the subviews of the content view, and call setEnabled: on all of them. This might break the scroll view by disabling some internal view, so don't iterate on the subview property of the scroll view itself. To prevent calling setEnabled: on views that don't have an enabled property, use respondsToSelector:@selector(setEnabled:) to check.

这篇关于Cocoa:禁用视图中所有控件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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