【发布时间】:2015-06-02 09:48:49
【问题描述】:
我正在开发 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)
}
}
在查看是否加载时出现错误,因为“此类不符合关键属性的关键值编码”
【问题讨论】:
-
哪一行报错
-
properties = self.valueForKey("properties") as! [Property]的意图是什么? -
@Memon...sortingPopoverController.setValue(properties, forKey: "properties") //我将此数组传递给“排序控制器”............ ..........line 出错
-
@JefferyThomas...它将获取“properties”的集合对象..我假设..........properties = self.valueForKey("properties") as! [属性]
-
self.valueForKey("properties")返回与self.properties相同的对象,所以你说的是properties = properties as! [Property]。
标签: swift uipopovercontroller popover