【发布时间】:2015-04-24 19:00:58
【问题描述】:
我正在一个分区表中实现一个带有 UISearchController 的搜索栏。到目前为止一切顺利。
主要问题是,当过滤后的结果出现时,它是一个全新的表,没有节,行也更少。
When selecting the row, I perform a segue to that position in the array, but the detailed view is expecting that exact row or index from the main array, which I can't get from the filtered array of objects, which may在 300 个元素中为 [0] [1] [2]。
我想我可以将所选对象与主数组进行比较,并假设没有重复项,从那里获取索引并将其传递……但这些对我来说似乎效率很低。
在联系人应用程序中过滤联系人时,Apple 做了类似的事情(不幸的是我不知道如何)。他们如何传递联系对象?这几乎就是我的目标。
在这里,我让您了解一下我正在做的事情:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(self.resultSearchController.active) {
customerAtIndex = indexPath.row // Issue here
performSegueWithIdentifier("showCustomer", sender: nil)
}
else {
customerAtIndex = returnPositionForThisIndexPath(indexPath, insideThisTable: tableView)
performSegueWithIdentifier("showCustomer", sender: nil)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showCustomer" {
if let destination = segue.destinationViewController as? CustomerDetailViewController {
destination.newCustomer = false
destination.customer = self.customerList[customerAtIndex!]
destination.customerAtIndex = self.customerAtIndex!
destination.customerList = self.customerList
}
}
}
【问题讨论】:
标签: ios uitableview swift