gpt4 book ai didi

Swift,此类不符合键 "array"的键值编码

转载 作者:行者123 更新时间:2023-11-30 10:15:01 24 4
gpt4 key购买 nike

我正在开发弹出窗口 Controller ,在打开弹出窗口时,我将数组(属性)传输到popoverController(SortingPopoverController)。对于 View ,我创建了popView.xib,并在firstOwner中附加了“SortingPopovercontroller”。

我的代码如下

    func sortingPressed(sender: AnyObject){
var sortingPopView = SortingPopoverController(nibName: "PopView",bundle: nil )

var sortingPopoverController = UIPopoverController(contentViewController: sortingPopView)

sortingPopoverController.popoverContentSize = CGSize(width: 250, height: 100)


sortingPopoverController.presentPopoverFromBarButtonItem(sortingBtn, permittedArrowDirections: UIPopoverArrowDirection.Up
, animated: true)

sortingPopoverController.setValue(properties, forKey: "properties") //i am passing this array to the "sorting controller"

}

///排序 Controller 代码

    class SortingPopoverController: UIViewController
{
var properties:[Property] = [Property]()
var propertyNameSrt = false
var addressSrt = false
var ascSorting = false
var utility = Utility()

override func viewDidLoad()
{
super.viewDidLoad()

let propertyNameSorting = UITapGestureRecognizer(target: self, action: "propertyNameSorting:")
self.propertyNameView.addGestureRecognizer(propertyNameSorting)

let addressSorting = UITapGestureRecognizer(target: self, action: "addressSorting:")
self.addressNameView.addGestureRecognizer(addressSorting)
imgTickPropertyName.hidden = true
imgTickAddress.hidden = true

properties = self.valueForKey("properties") as! [Property]
println(properties.count)

}
}

在 View 确实加载时,我收到错误,因为“此类的关键属性不符合键值编码

最佳答案

sortingPopoverController 是一个 UIPopoverController。您打算使用 sortingPopView,其中包含 SortingPopoverController

sortingPopView.setValue(properties, forKey: "properties") //i am passing this array to the "sorting controller"
<小时/>

不需要 Key-Value Coding语法在这里。

sortingPopView.properties = properties

会做同样的事情。注意:上面的内容也是类型安全的,因此如果 sortingPopView.propertiesproperties 的类型不同,您将收到警告或错误。

关于Swift,此类不符合键 "array"的键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592676/

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