Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我试图弄清楚如何使用xib文件创建自定义视图. 在此 question中,使用下一个方法. NSBundle.mainBundle().loadNibNamed("CardView", owner: nil, options: nil)[0] as! UIView Cocoa具有相同的方法,但是,这个方法在swift 3到loadNibNamed(_:owner:topLevelObjects:) 我试图弄清楚如何使用xib文件创建自定义视图.
在此 question中,使用下一个方法.
NSBundle.mainBundle().loadNibnamed("CardVIEw",owner: nil,options: nil)[0] as! UIVIEw

Cocoa具有相同的方法,但是,这个方法在swift 3到loadNibNamed(_:owner:topLevelObjects:)中已经改变,它返回Bool,并且之前的代码生成“Type Bool没有下标成员”错误,这很明显,因为返回类型是Bool.

所以,我的问题是如何从Swift 3中的xib文件加载视图

首先,Swift 3中没有改变该方法.

loadNibnamed(_:owner:topLevelObjects :)已经在macOS 10.8中引入,并且存在于所有版本的Swift中.但是,在Swift 3中删除了loadNibnamed(nibname:owner:options :).

该方法的签名是

func loadNibnamed(_ nibname: String,owner: Any?,topLevelObjects: autoreleasingUnsafeMutablePointer<NSArray>?) -> Bool

所以你必须创建一个指针来获取返回的视图数组.

var topLevelObjects = NSArray()if Bundle.main.loadNibnamed("CardVIEw",owner: self,topLevelObjects: &topLevelObjects) {   let vIEws = (topLevelObjects as Array).filter { 
var topLevelObjects : NSArray?if Bundle.main.loadNibnamed(assistantNib,topLevelObjects: &topLevelObjects) {     return topLevelObjects!.first(where: { [+++] is NSVIEw }) as? NSVIEw}
is NSVIEw } return vIEws[0] as! NSVIEw}

编辑:我更新了答案,可靠地过滤NSVIEw实例.

在Swift 4中,语法略有改变并首先使用(其中效率更高:

[+++] 总结

以上是内存溢出为你收集整理的可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool全部内容,希望文章能够帮你解决可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我试图弄清楚如何使用xib文件创建自定义视图. 在此 question中,使用下一个方法. NSBundle.mainBundle().loadNibNamed("CardView", owner: nil, options: nil)[0] as! UIView Cocoa具有相同的方法,但是,这个方法在swift 3到loadNibNamed(_:owner:topLevelObjects:) 我试图弄清楚如何使用xib文件创建自定义视图.
在此 question中,使用下一个方法.
NSBundle.mainBundle().loadNibnamed("CardVIEw",owner: nil,options: nil)[0] as! UIVIEw

Cocoa具有相同的方法,但是,这个方法在swift 3到loadNibNamed(_:owner:topLevelObjects:)中已经改变,它返回Bool,并且之前的代码生成“Type Bool没有下标成员”错误,这很明显,因为返回类型是Bool.

所以,我的问题是如何从Swift 3中的xib文件加载视图

首先,Swift 3中没有改变该方法.

loadNibnamed(_:owner:topLevelObjects :)已经在macOS 10.8中引入,并且存在于所有版本的Swift中.但是,在Swift 3中删除了loadNibnamed(nibname:owner:options :).

该方法的签名是

func loadNibnamed(_ nibname: String,owner: Any?,topLevelObjects: autoreleasingUnsafeMutablePointer<NSArray>?) -> Bool

所以你必须创建一个指针来获取返回的视图数组.

var topLevelObjects = NSArray()if Bundle.main.loadNibnamed("CardVIEw",owner: self,topLevelObjects: &topLevelObjects) {   let vIEws = (topLevelObjects as Array).filter { 
var topLevelObjects : NSArray?if Bundle.main.loadNibnamed(assistantNib,topLevelObjects: &topLevelObjects) {     return topLevelObjects!.first(where: {  is NSVIEw }) as? NSVIEw}
is NSVIEw } return vIEws[0] as! NSVIEw}

编辑:我更新了答案,可靠地过滤NSVIEw实例.

在Swift 4中,语法略有改变并首先使用(其中效率更高:

[+++] 总结

以上是内存溢出为你收集整理的可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool全部内容,希望文章能够帮你解决可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool_app_内存溢出

可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool

可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool,第1张

概述我试图弄清楚如何使用xib文件创建自定义视图. 在此 question中,使用下一个方法. NSBundle.mainBundle().loadNibNamed("CardView", owner: nil, options: nil)[0] as! UIView Cocoa具有相同的方法,但是,这个方法在swift 3到loadNibNamed(_:owner:topLevelObjects:) 我试图弄清楚如何使用xib文件创建自定义视图.
在此 question中,使用下一个方法.
NSBundle.mainBundle().loadNibnamed("CardVIEw",owner: nil,options: nil)[0] as! UIVIEw

Cocoa具有相同的方法,但是,这个方法在swift 3到loadNibNamed(_:owner:topLevelObjects:)中已经改变,它返回Bool,并且之前的代码生成“Type Bool没有下标成员”错误,这很明显,因为返回类型是Bool.

所以,我的问题是如何从Swift 3中的xib文件加载视图

首先,Swift 3中没有改变该方法.

loadNibnamed(_:owner:topLevelObjects :)已经在macOS 10.8中引入,并且存在于所有版本的Swift中.但是,在Swift 3中删除了loadNibnamed(nibname:owner:options :).

该方法的签名是

func loadNibnamed(_ nibname: String,owner: Any?,topLevelObjects: autoreleasingUnsafeMutablePointer<NSArray>?) -> Bool

所以你必须创建一个指针来获取返回的视图数组.

var topLevelObjects = NSArray()if Bundle.main.loadNibnamed("CardVIEw",owner: self,topLevelObjects: &topLevelObjects) {   let vIEws = (topLevelObjects as Array).filter { 
var topLevelObjects : NSArray?if Bundle.main.loadNibnamed(assistantNib,topLevelObjects: &topLevelObjects) {     return topLevelObjects!.first(where: {  is NSVIEw }) as? NSVIEw}
is NSVIEw } return vIEws[0] as! NSVIEw}

编辑:我更新了答案,可靠地过滤NSVIEw实例.

在Swift 4中,语法略有改变并首先使用(其中效率更高:

总结

以上是内存溢出为你收集整理的可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool全部内容,希望文章能够帮你解决可可 – Swift 3加载xib. NSBundle.mainBundle().loadNibNamed返回Bool所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1029442.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存