2016-04-22 76 views
1

嘿,我在項目中使用AKSwiftSlideMenu作爲幻燈片菜單功能,我不知道是否有一種方法,以便我可以在菜單中繼續查看目標ViewController標題?我想這個代碼,但沒有將數據傳遞到目的地:如何將數據從AKSwiftSlideMenu菜單傳遞給Swift中的UIViewController?

func slideMenuItemSelectedAtIndex(index: Int32) { 
let topViewController : UIViewController = self.navigationController!.topViewController! 
print("View Controller is : \(topViewController) \n", terminator: "") 
switch(index){ 
case 0: 
    print("Note\n", terminator: "") 
    var nextVC = AddSubcategoryVC() 
    nextVC.categoryName = "Note" 
    self.openViewControllerBasedOnIdentifier("AddSubcategoryVC") 
    print("On menu the cat is: \(nextVC.categoryName)") 
    break 
default: 
    print("default\n", terminator: "") 
} 
} 

在視圖控制器我有這個變量,從菜單中獲取數據的目標:

var categoryName = "" 

和它返回'零'。我也試着這樣做:

var categoryName : String! 

這:

var categoryName = String() 

所有返回 '零'。

回答

0

您已經創建了視圖控制器的新對象。

替換此代碼:

var nextVC = AddSubcategoryVC() 
nextVC.categoryName = "Note" 
self.openViewControllerBasedOnIdentifier("AddSubcategoryVC") 

let destViewController = self.storyboard!.instantiateViewControllerWithIdentifier("AddSubcategoryVC") as! AddSubcategoryVC 
destViewController.categoryName = "Note"// You have to pass your data with view controller witch will open 
let topViewController : UIViewController = self.navigationController!.topViewController! 

if (topViewController.restorationIdentifier! == destViewController.restorationIdentifier!){ 
    print("Same VC") 
} else { 
    self.navigationController!.pushViewController(destViewController, animated: true) 
} 
相關問題