0

我在我的表格视图中创建了 UIsearch 栏进行搜索,一切正常,但是当我想将数据从过滤数组传递到另一个控制器时出现问题,在我进行搜索之后,我准备好了

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


    }
    }

}

此代码适用于非搜索数据我应该编写哪些代码来传递搜索数据

4

2 回答 2

0

在目标视图控制器上声明对象并直接访问。检查下面的代码。

//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)")
}
于 2014-11-19T12:11:38.650 回答
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


    }
    }

}
于 2014-09-13T18:22:27.503 回答