我让UIsearch栏在我的tableview中搜索,一切正常,但是当我想要将数据从过滤后的数组传递到另一个控制器后,问题进行了搜索后, 在这里我的准备
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ahmed" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
print(indexPath.row)
var object = Persons[indexPath.row]
(segue.destinationViewController as DetailViewController).name = object.name
}
}
}
此代码适用于非搜索数据,我应编写哪些代码来传递搜索数据
答案 0 :(得分:0)
我添加此代码并且可以正常工作
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ahmed" {
if((searchDisplayController?.active) != nil)
{
if let indexpath=searchDisplayController?.searchResultsTableView.indexPathForSelectedRow()
{
var object=filtered[indexpath.row]
(segue.destinationViewController as DetailViewController).name = object.name
}
}
if let indexPath = self.tableView.indexPathForSelectedRow() {
print(indexPath.row)
var object = Persons[indexPath.row]
(segue.destinationViewController as DetailViewController).name = object.name
}
}
}
答案 1 :(得分:0)
在Destination视图控制器中声明对象并直接访问。检查以下代码。
//Destination View controller
import UIKit
var marCategoryList : NSMutableArray!
class tsCategoryViewController: UIViewController {
// Source view controller
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
var objTest = tsCategoryViewController()
let marImageNam = NSMutableArray(objects:"1.jpeg","2.jpeg","3.jpeg","4.jpeg","5.jpeg","6.jpeg","7.jpeg","8.jpeg","9.jpeg","10.jpeg")
marCategoryList = marImageNam
println("\(marCategoryList)")
}