2015-09-11 61 views
0

我想將數據從一個UIView傳遞到另一個UIView,以便訪問根據用戶選擇的UITabBarItem而不同的網站。我該怎麼做?以segue形式傳遞數據UITabBarItem不起作用

func pathButton(dcPathButton: DCPathButton!, clickItemButtonAtIndex itemButtonIndex: UInt) { 

    switch itemButtonIndex { 

    case 0: 

    // working but can’t send data with it 
    self.performSegueWithIdentifier("goto", sender: self) 

    // not working as function is not trigger 
    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 
     if segue.identifier == "goto" { 
      let vc = segue.destinationViewController as! WebMainViewController 
      vc.goURL = "http://google.com「 

     dcPathButton.delegate = self 

     println(「go to http//google.com」) 
     } 
    case 1: 
     println(「go to http://apple.com」) 
    case 2: 
     println(「go to http://imbd.com」) 
    case 3: 
     println(「go to http://facebook.com」) 
    default: 
     println(「go to http://cnn.com」) 
    } 

回答

0

你試過

func pathButton(dcPathButton: DCPathButton!, clickItemButtonAtIndex itemButtonIndex: UInt) { 
switch itemButtonIndex { 
case 0: 
    self.performSegueWithIdentifier("goto", sender: self) 
    // plus other cases 
} 

,然後在你的類的不同部分,您實現:

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 
    if segue.identifier == "goto" { 
     let vc = segue.destinationViewController as! WebMainViewController 
     vc.goURL = "http://google.com「 
} 

顯然確保您賽格瑞掛起來,有「轉到「設置爲標識符

也許你可以在prepareForSegue中設置一些邏輯來設置vc.goURL而不是你現在擁有的switch語句?例如,用戶選擇一個特定的值,將這個值保存到一個變量中,然後當他們點擊一個按鈕開始搜索時,檢查該變量的值並相應地設置vc.goURL