2015-09-11 29 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