- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我发现 NSBundle 中的 NSNibLoading 方法:
+[NSBundle loadNibFile:externalNameTable:withZone:]
+[NSBundle loadNibNamed:owner:]
-[NSBundle loadNibFile:externalNameTable:withZone:]
在 10.8 中都已标记为弃用 - 在 10.8 及更高版本中加载 nib 的正确方法是什么?
我正在尝试在我的应用程序中创建自定义工作表,我是否必须为自定义工作表创建带有 initWithWindowNibName
的 NSWindowController
?
最佳答案
如果您的应用程序要支持 Lion,那么 loadNibNamed:owner:topLevelObjects:
将不会触发,并且在 Lion 上运行时您将得到一个异常(无法识别的选择器)。经过一番搜索后,我想到了这个:
// loadNibNamed:owner:topLevelObjects was introduced in 10.8 (Mountain Lion).
// In order to support Lion and Mountain Lion +, we need to see which OS we're
// on. We do this by testing to see if [NSBundle mainBundle] responds to
// loadNibNamed:owner:topLevelObjects: ... If so, the app is running on at least
// Mountain Lion... If not, then the app is running on Lion so we fall back to the
// the older loadNibNamed:owner: method. If your app does not support Lion, then
// you can go with strictly the newer one and not deal with the if/else conditional.
if ([[NSBundle mainBundle] respondsToSelector:@selector(loadNibNamed:owner:topLevelObjects:)]) {
// We're running on Mountain Lion or higher
[[NSBundle mainBundle] loadNibNamed:@"NibName"
owner:self
topLevelObjects:nil];
} else {
// We're running on Lion
[NSBundle loadNibNamed:@"NibName"
owner:self];
}
如果你真的想为 Mountain Lion + 使用 topLevelObjects:&array
,并且你还想支持 Lion,看起来你需要退回到 loadNibFile:externalNameTable:withZone:(可用作为类和实例方法)用于 Lion 条件(我对这个可能是错误的)。我的印象是创建了 loadNibNamed:owner:topLevelObjects:
来替换它。
我还在其他地方读到,当使用较新的 loadNibNamed:owner:topLevelObjects:
工作表时,您应该取消选中工作表(窗口)的“关闭时释放”。关闭工作表时应注意这一点:
[self.sheet close];
self.sheet = nil;
如果您打开非模态窗口,我不确定应该如何处理该复选框。有什么想法吗?
关于objective-c - 替换已弃用的 NSNibLoading 方法(loadNibFile :, loadNibNamed :, 等)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12767838/
我知道这很直截了当,但经过太多的牵扯,我离解决方案还差得很远。 我看过解释如何使用 XIB 和所有内容创建 View 的教程。但他们都没有解决我在这里遇到的情况。 我有一个 XIB 文件,它是一个自定
我即将完成我的第一个 iPhone 应用程序,并想通过 Leaks Performance Tool 运行它。修复了一个明显的问题后,我剩下的唯一一个是一个 Nib 充当通过 loadNibNamed
由于某种原因,使用 loadNibNamed: 导致内存泄漏。 假设我有接口(interface): @interface Step : UIViewController { IBOutlet U
我正在使用 loadView 以编程方式设置 UIViewController 子类,并且想知道我是否做对了。当我在 Interface Builder 中查看“Interface.xib”时,其 V
我正在尝试使用 iPhone SDK 更改使用 Nib 创建的对象的类。 原因是;直到运行时我才知道我想要的 nib 对象是什么类(尽管它们将具有相同的基于 UIView 的父类(super clas
我实现了一个 loadNibNamed: 方法来唤醒一些窗口。 打开的窗口不是事件的。我怎样才能使这个窗口成为当前窗口,什么时候加载? 最佳答案 [窗口 makeKeyAndOrderFront: n
这是场景:一个简单的应用程序,有两个 View Controller 类和一个带有 1 个 View Controller 的 Storyboard。 ViewController 'Super' 继
我有类层次结构 ParentCell extends UITableViewCell ChildCell extends ParentCell ParentCell 有单独的 XIB,在子单元中,我仅
当我们使用loadNibNamed方法获取nib文件时,为什么会返回一个数组,不就是一个nib文件名对应一个nib文件吗?我尝试打印这个数组的计数,我发现它总是返回1。希望你能帮我解释一下,非常感谢!
我正在尝试在用户按下按钮时使用 loadnibnamed 加载名为“AddProgramView”的 xib 文件。我在 Storyboard中创建了 xib,在 xib View 中放置了各种 su
Apple Doc 说 nib 文件中最重要的对象之一是 File's Owner 对象 ,但它似乎是 nib 文件中的文件所有者,而不是 LoadNibName< 设置的对象 方法。我想知道它们之间
我熟悉为我自己的 UIView 子类创建 XIB 的大部分过程,但并非一切都对我正常工作——这主要与 IBOutlets 链接有关。我可以让他们以一种看似迂回的方式工作。 我的设置是这样的: 我有 M
我使用以下代码从 View Controller 中正确加载 Nib (XIB): self.myView.view = (MyView *)[[[NSBundle mainBundle] loadN
我有一个基于文档的 Cocoa 应用程序。在运行时,我通过调用 [NSBundle loadNibNamed:@"inspectorNIB"owner:self] 从包中加载额外的 Nib (其中 s
我正在尝试使用自定义 nib 文件来完成 UITableViewCell 的子类。 子类的名称是 MyCustomCell。 .xib 文件只有一个带有单个 UILabel“cellTitle”的 U
我创建了一个与 .xib 文件关联的 UIView 子类。此 UIView 子类将在 UIViewController 中使用。在 Controller 中,我认为我们如何实例化 UIView 子类有
我有一个带有 CustomClass = "BaseClass"的 view.xib 文件(我在 XCode 编辑器上配置它),所以我可以这样做: BaseClass *mBassClass= [[[
我正在使用自定义单元格并调用 loadNibNamed:。这似乎会导致内存泄漏,我不确定如何解决。如果之后我将顶级对象设置为 nil,我仍然会遇到泄漏。 topLevelObjects = [[NSB
我有一个 View Controller ,其中包含许多自定义 UIView。我尝试使用 InterfaceBuilder (IB) 定义自定义 UIView,并使用以下代码在 initWithFra
我有一个 ScrollView ,其中包含大约 40-50 个不同类型的对象。对象的类型根据对象的位置定义(例如,如果是 ScrollView 中的第 5 个对象 -> 是 Object1,如果它是
我是一名优秀的程序员,十分优秀!