将Object从一个ViewController传递到另一个ViewController

时间:2015-06-15 11:56:58

标签: ios swift uiviewcontroller segue

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "shoesDetails" {
        let indexPath = self.table.indexPathForSelectedRow()    
        let shoesCon:ShoesTableControler = segue.destinationViewController as! ShoesTableControler
        let shoesCategories:RepoSitory = arrofRepository[indexPath!.row]       
        shoesCon.object = shoesCategories
    }
 }

class ShoesTableControler: UIViewController {
    var object = [ProductShoes]()
}

class ProductShoes {
    var product_id : String
    var product_name : String

    init(json :NSDictionary) {
        self.product_id = json["product_id"] as! String
        self.product_name = json["product_name"] as! String
    } 
    class RepoSitory {
var name : String
var ids : String

init(json :NSDictionary) {
   self.name = json["category_name"] as! String
   self.ids = json["id"] as! String



}

}

我在firstViewController中有3个类。我们展示了它完成的数据。之后,当用户单击特定单元格时,则显示数据。现在我已经创建了ShoesTableController,在ShoesTableController中我们创建了Product Class obj。我想访问它。问题在于目标C中的这一行。我正在做这个并且它工作得很完美但是它很快就知道发生了什么:

 shoesCon.object = shoesCategories 

1 个答案:

答案 0 :(得分:1)

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "shoesDetails" {


    let indexPath = self.table.indexPathForSelectedRow()


   let shoesCon:ShoesTableControler = segue.destinationViewController as! ShoesTableControler
    let shoesCategories:RepoSitory = arrofRepository[indexPath!.row]

       shoesCon.object = shoesCategories
         }
    }

 class ShoesTableControler: UIViewController {

var object : RepoSitory?

它解决了我的问题我有自己的错误抱歉发布这个问题