【问题标题】:Pass data with segue form UITabBarItem not working使用 segue 表单 UITabBarItem 传递数据不起作用
【发布时间】:2015-09-11 15:50:22
【问题描述】:

我想将数据从一个 UIView 传递到另一个 UIView,以便访问根据用户选择的 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”)
    }

【问题讨论】:

    标签: xcode swift segue uitabbar


    【解决方案1】:

    你试过了吗

    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“
    }
    

    显然确保您的 segue 已连接并将“goto”设置为标识符

    也许您可以在prepareForSegue 中设置一些逻辑来设置vc.goURL,而不是您当前拥有的switch 语句?例如,用户选择了一个特定的值,您将该值保存到一个变量中,然后当他们单击按钮启动 segue 时,您检查该变量的值并相应地设置vc.goURL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 2015-10-01
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多