1

嘿伙计们,我在项目中使用 AKSwiftSlideMenu 来实现幻灯片菜单功能,我想知道是否有办法让我在从菜单中选择目标 ViewController 标题时更改它?我尝试了这段代码,但没有将数据传递到目的地:

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 = ""

它返回'nil'。我也试过这样做:

var categoryName : String!

和这个:

var categoryName = String()

全部返回“零”。

4

1 回答 1

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)
}
于 2016-07-20T07:38:02.060 回答