Swift,这个类不是键值编码兼容键“数组”

时间:2015-06-02 09:48:50

标签: swift uipopovercontroller popover

我正在开发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)

                }
        }

在视图上加载我收到错误“此类不是关键属性的关键值编码兼容

1 个答案:

答案 0 :(得分:1)

sortingPopoverControllerUIPopoverController。您打算使用sortingPopView,其中包含SortingPopoverController

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

此处不应该需要Key-Value Coding语法。

sortingPopView.properties = properties

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