gpt4 book ai didi

iOS 和 UIKit 类检查

转载 作者:行者123 更新时间:2023-11-28 20:42:17 26 4
gpt4 key购买 nike

如何以编程方式检查 UIKit 是否有给定的类?

例如,在 iOS3 上没有 UINib,但在 iOS4 上有。我可以在 SDK4 上构建,但如果我尝试在 iOS3.0 设备上运行,我会遇到异常。

最佳答案

iOS 4 release notes状态:

iOS 4 includes a new UINib class to support rapidly unarchiving nib files. While this class is new to iOS SDK 4, it was present but private, in previous releases. Special care needs to be taken when deploying code that uses the UINib class and also runs on iOS releases prior to version 4. Specifically, you cannot determine the availability of the class solely using the NSClassFromString function, because that check returns a private class on iOS 3.x and earlier. Instead, after getting the UINib class using NSClassFromString, you must also use the respondsToSelector: method of the returned class to see if it responds to the nibWithNibName:bundle: method. If it responds to that method, you can use the class.

关于iOS 和 UIKit 类检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7991608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com