【问题标题】:Passing the Object from one ViewController to another将对象从一个 ViewController 传递到另一个
【发布时间】:2015-06-15 11:56:58
【问题描述】:
 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。我想访问这个。问题出在Objective C中的这一行。我正在这样做并且它运行良好,但它很快就知道发生了什么:

 shoesCon.object = shoesCategories 

【问题讨论】:

  • 我看到了这个,但我的问题是不同的兄弟
  • 然后作为开始,您需要解释什么不起作用。发生了什么?有编译时错误吗?它崩溃了吗?是发射导弹吗?发生了什么与您的预期不同?
  • 兄弟,对不起,我认为你介意错误是“无法将 Class 类型的值分配给 ProductShoes 类型的值”
  • 无法将 RepoSitory 类型的值分配给 ProductShoes 类型的值

标签: ios swift uiviewcontroller segue


【解决方案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?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-25
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    相关资源
    最近更新 更多