我正在开发popover控制器,在打开popover时我将Array(属性)传递给popoverController(SortingPopoverController)。对于视图我创建了popView.xib,在firstOwner中,我附加了“SortingPopovercontroller”。 / p>
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"
}
///排序控制器代码
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)
}
}
在视图上加载我收到错误“此类不是关键属性的关键值编码兼容”
答案 0 :(得分:1)
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.properties
和properties
属于不同类型,您将收到警告或错误。