SortingPopoverController

SortingPopoverController

我正在开发popover控制器,并在打开popover时将数组(属性)传输到popoverController(SortingPopoverController)。对于视图,我创建了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"

  }


///排序控制器代码

    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)

                }
        }


在视图上确实加载了,但由于“此类不符合键属性的键值编码标准”,我收到了错误消息

最佳答案

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是不同的类型,则会收到警告或错误。

10-08 09:05