Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未触发展开段 我一直在学习SWIFT,并为我的大多数应用程序奠定了基础。我有下面的故事板_Swift_Uiviewcontroller_Segue_Unwind Segue - Fatal编程技术网

未触发展开段 我一直在学习SWIFT,并为我的大多数应用程序奠定了基础。我有下面的故事板

未触发展开段 我一直在学习SWIFT,并为我的大多数应用程序奠定了基础。我有下面的故事板,swift,uiviewcontroller,segue,unwind-segue,Swift,Uiviewcontroller,Segue,Unwind Segue,一切正常。例如,我在“添加课程”视图控制器上有一个“展开”序列,当您按“保存”并返回到“您的课程”视图控制器时会触发该序列 当您在“我的课程”视图控制器上时,您可以选择一门课程并显示主题,然后您可以选择一个主题并转到“更新分数”视图控制器,这一切都可以正常工作 然而,我的问题是这个。我希望这样,当您在UpdateCore视图控制器中选择save时,会触发一个展开序列(与add课程中相同),并返回到topics视图控制器中的主题列表 然而,我已经学习了很多教程,而且很明显我以前就已经学好了。(我的

一切正常。例如,我在“添加课程”视图控制器上有一个“展开”序列,当您按“保存”并返回到“您的课程”视图控制器时会触发该序列

当您在“我的课程”视图控制器上时,您可以选择一门课程并显示主题,然后您可以选择一个主题并转到“更新分数”视图控制器,这一切都可以正常工作

然而,我的问题是这个。我希望这样,当您在UpdateCore视图控制器中选择save时,会触发一个展开序列(与add课程中相同),并返回到topics视图控制器中的主题列表

然而,我已经学习了很多教程,而且很明显我以前就已经学好了。(我的展开序列操作方法位于正确的“主题”视图控制器中),但当我按“保存”时,展开序列不会将我返回到“主题”视图控制器

有人能提出这样做的原因吗?我花了很多时间试图找到一个答案,并通过了许多教程,但没有设法解决它

我还为我的保存按钮添加了一个触发序列连接的屏幕截图,以显示它已设置

我在更新分数视图控制器中有以下代码

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if saveButton === sender {
        print("save button selected")
   }
}
但当我点击save时,即使是这样也不会触发

非常感谢

更新: 在遵循Ronatory的建议后,我的视图控制器的更新分数如下所示,但仍不起作用:

导入UIKit

类UpdateCoreTableViewController:UITableViewController{

@IBOutlet weak var topicGettingUpdated: UITextField!
@IBOutlet weak var newScore: UITextField!


@IBOutlet weak var saveButton: UIBarButtonItem!


var index:Int?
var Topics:[String]!


var TopicToUpdate:String?


override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
        print("There is no UIBarButtonItem sender")
        return
    }
}


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.section == 0 && indexPath.row == 0 {
        newScore.becomeFirstResponder()
    }
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}


但是“为segue做准备”甚至没有被触发。

就像Craig在评论中说的那样,发现问题并不是那么容易。因此,我只是构建了一个简单的应用程序,您可以按照指南中的步骤进行操作,看看是否忘记了正确设置功能。希望它能帮助你注意:代码在Swift 3.0中,但在2中应易于采用。*

1。带有两个视图控制器的情节提要:

class FirstViewController: UIViewController {
  // action method for the unwind segue
  @IBAction func updateScore(_ segue: UIStoryboardSegue) {
    print("Back in the FirstViewController")
  } 
}
class SecondViewController: UIViewController {

  @IBOutlet weak var saveButtonPressed: UIBarButtonItem!

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // check safely with guard that your save button is the sender and you can use it
    // if not print message
    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
      print("There is no UIBarButtonItem sender")
      return
    }

    // check if you selected the save button
    if saveButtonPressed == uiBarButtonItem {
      print("save button selected")
    }
  }
}

2。在
FirstViewController.swift

class FirstViewController: UIViewController {
  // action method for the unwind segue
  @IBAction func updateScore(_ segue: UIStoryboardSegue) {
    print("Back in the FirstViewController")
  } 
}
class SecondViewController: UIViewController {

  @IBOutlet weak var saveButtonPressed: UIBarButtonItem!

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // check safely with guard that your save button is the sender and you can use it
    // if not print message
    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
      print("There is no UIBarButtonItem sender")
      return
    }

    // check if you selected the save button
    if saveButtonPressed == uiBarButtonItem {
      print("save button selected")
    }
  }
}
3。将情节提要中的
保存按钮
与操作方法(按住ctrl键并拖动)连接起来:

class FirstViewController: UIViewController {
  // action method for the unwind segue
  @IBAction func updateScore(_ segue: UIStoryboardSegue) {
    print("Back in the FirstViewController")
  } 
}
class SecondViewController: UIViewController {

  @IBOutlet weak var saveButtonPressed: UIBarButtonItem!

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // check safely with guard that your save button is the sender and you can use it
    // if not print message
    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
      print("There is no UIBarButtonItem sender")
      return
    }

    // check if you selected the save button
    if saveButtonPressed == uiBarButtonItem {
      print("save button selected")
    }
  }
}

4。将
保存按钮
SecondViewController.swift
文件连接,以使用它检查
prepareSegue
方法(按住ctrl键并拖动):

class FirstViewController: UIViewController {
  // action method for the unwind segue
  @IBAction func updateScore(_ segue: UIStoryboardSegue) {
    print("Back in the FirstViewController")
  } 
}
class SecondViewController: UIViewController {

  @IBOutlet weak var saveButtonPressed: UIBarButtonItem!

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // check safely with guard that your save button is the sender and you can use it
    // if not print message
    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
      print("There is no UIBarButtonItem sender")
      return
    }

    // check if you selected the save button
    if saveButtonPressed == uiBarButtonItem {
      print("save button selected")
    }
  }
}

5。将
prepare(for:sender:)
方法添加到您的
SecondViewController.swift

class FirstViewController: UIViewController {
  // action method for the unwind segue
  @IBAction func updateScore(_ segue: UIStoryboardSegue) {
    print("Back in the FirstViewController")
  } 
}
class SecondViewController: UIViewController {

  @IBOutlet weak var saveButtonPressed: UIBarButtonItem!

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // check safely with guard that your save button is the sender and you can use it
    // if not print message
    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
      print("There is no UIBarButtonItem sender")
      return
    }

    // check if you selected the save button
    if saveButtonPressed == uiBarButtonItem {
      print("save button selected")
    }
  }
}
结果:

class FirstViewController: UIViewController {
  // action method for the unwind segue
  @IBAction func updateScore(_ segue: UIStoryboardSegue) {
    print("Back in the FirstViewController")
  } 
}
class SecondViewController: UIViewController {

  @IBOutlet weak var saveButtonPressed: UIBarButtonItem!

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // check safely with guard that your save button is the sender and you can use it
    // if not print message
    guard let uiBarButtonItem = sender as? UIBarButtonItem else {
      print("There is no UIBarButtonItem sender")
      return
    }

    // check if you selected the save button
    if saveButtonPressed == uiBarButtonItem {
      print("save button selected")
    }
  }
}


您可以找到的示例应用程序

我没有设法让“放松”序列正常工作,而是使用了它

navigationController!.popViewControllerAnimated(true)

作为一种解决方法,这很好。

如果没有更多信息,很难帮助您解决此问题。
prepareForSegue
没有被触发,这一事实仅仅证实了放卷阶段没有工作。嗨,Ronational,非常感谢,但它没有工作。我尝试按照您的所有步骤进行操作,但当我按“保存”时仍然没有任何结果。prepare for segue甚至没有被触发,控制台中也没有显示“没有UIBarButtonItem发送器”。我想也许导航控制器有一些我不了解的地方。因此,我已经删除了导航控制器,其中嵌入了更新分数,一切正常,我理解这一点,即我可以通过堆栈导航回去。正是在这一点上,我无法让保存按钮工作。