放宽搜寻未触发 [英] unwind segue not triggering

查看:148
本文介绍了放宽搜寻未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习快速,并为我的大多数应用奠定了基础.我有以下情节提要

I have been learning swift and have made the foundation of most of my app. I have the following storyboard

应用故事板

一切正常.例如,我在添加课程视图控制器上有一个放松的选择,当您按保存并触发您回到您的课程"视图控制器时,就会触发.

Everything works fine. For example, I have an unwind segue on the add course view controller that triggers when you press save and you are returned to the 'your courses' view controller.

当您在我的课程"视图控制器上时,可以选择一个课程并显示主题,然后可以选择一个主题,然后转到更新分数"视图控制器,这一切都很好.

When you are on the my courses view controller, you can select a course and the topics are displayed, you can then select a topic and you are taken to an update score view controller, this all works fine.

但是,我的问题是这个.我要这样做,以便当您在Updatescore视图控制器中选择保存"时,将触发取消同步(与添加过程中一样),并且您将返回到主题视图控制器中的主题列表.

However, my problem is this. I want to make it so that when you select save in the updatescore view controller, an unwind segue is triggered (the same as in the add course) and you are returned to the list of topics in the topics view controller.

但是,我遵循了许多教程,并且显然可以使它工作. (我用于解散键的动作方法是在正确的主题视图控制器中),但是当我按保存时,解散键不会使我返回主题视图控制器.

However, I have followed many tutorials and obviously got it working before. (My action method for the unwind segue is in the correct topics view controller) but when i press save, the unwind segue is not returning me to the topics view controller.

有人可以提出原因吗?我花了很多时间试图找到答案,并完成了许多教程,但都未能解决.

Could anyone suggest a reason for this? I have spent a lot of time trying to find an answer and gone through many tutorials but have not managed to solve it.

我还为我的保存"按钮提供了触发触发的序列的连接的屏幕快照,以显示它已设置. 显示保存"按钮的触发序列

I have also included a screen shot of the connections of the triggered segues for my save button to show that it is set up. Showing triggered segue for save button

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

i have the following code in the update score view controller

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if saveButton === sender {
        print("save button selected")
   }
}

但是,当我单击保存"时,甚至没有触发该事件.

But even this is not getting triggered when I click on save.

非常感谢

更新: 在遵循Ronatorys的建议后,我的更新分数的视图控制器如下,但仍无法正常工作:

UPDATE: After following Ronatorys advice My view controller for the update score is as follows but it is still not working:

导入UIKit

UpdateScoreTableViewController类:UITableViewController {

class UpdateScoreTableViewController: 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)
}

}

但是准备安全的准备甚至都没有触发.

But the prepare for segue is not even getting triggered.

推荐答案

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

Like Craig in the comments said, it's not that easy to find the problem. So I just build a simple app where you can follow the steps as guide and see if you forgot something to setup the functionality right. Hope it will help you. Note: Code is in Swift 3.0, but should be easy to adopt to 2.*

1.具有两个View Controller的情节提要:

2.在FirstViewController.swift中声明放松的动作方法:

2. Declare the action method for the unwind segue in the FirstViewController.swift:

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

3.使用动作方法(使用Ctrl +拖动)将情节提要中的Save button连接:

3. Connect the Save button in the Storyboard with the action method (with ctrl + drag):

4.将您的Save buttonSecondViewController.swift文件连接,以使用它来检查您的prepareSegue方法(使用ctrl +拖动):

4. Connect your Save button with the SecondViewController.swift file, to use it for checking in your prepareSegue method (with ctrl + drag):

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

5. Add the prepare(for:sender:) method to your SecondViewController.swift:

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")
    }
  }
}

结果:

您可以在此处找到示例应用程序

The sample app you can find here

这篇关于放宽搜寻未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆