Xcode 8.1出现问题并解散 [英] Having problems with Xcode 8.1 and unwind segues

查看:81
本文介绍了Xcode 8.1出现问题并解散的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法放松地使用最新的Xcode 8.1 GM.我只是想知道我是否是唯一的一个,或者其他人正在经历同样的事情.我已经像以前一样设置了视图控制器,它在Xcode 8.0中有效,但是现在我没有运气了.试图清洁等等,但是没有帮助.我希望其他人也可以在提交雷达之前对其进行测试...

I can't get unwind segue to work with the latest Xcode 8.1 GM. I'm just wondering if I'm the only one, or someone else is experiencing the same. I have set up the view-controllers as before, it worked in Xcode 8.0, but now I'm having no luck. Tried to clean and so on, but nothing helps. I would like someone else could test it as well before I file a radar...

首先实例化view controllerview controller具有以下代码:

The view controller that first instantiated the view controller is having the following code:

@IBAction func unwindToSettingsTableViewController(_ segue: UIStoryboardSegue) {
    print("unwind")
}

我也尝试不使用下划线,但这无济于事. 进行此设置时,应该可以ctrl从文件所有者中拖动以退出,并开始放松: 因此,或者我做错了什么(我认为不是,以前做得还不错),或者Xcode 8.1

I also tried without the underscore, but that did not help. When setting up this, one should be able to ctrl drag from files owner to exit, and get up the unwind segues: So either am I doing it completely wrong (I dont think so, it worked perfectly fine before), or there is a bug in Xcode 8.1

我尝试在一个新项目中执行相同的操作,然后它正常工作.所以我想我的项目或情节提要文件有问题.

I tried to do the same in a new project, and then it worked properly. So I guess there is something wrong with my project or storyboard file.

更新

由于情节提要板仅包含较小的场景,因此我将其删除,然后使用与视图控制器相同的类等再次创建它.现在就可以了.因此,拥有完全相同的代码,但有一个全新的故事板,使我认为这是一个错误.

Since the storyboards are holding rather small scenes, I just deleted it, and recreated it again, using the same classes for the view controllers and so on. And now it works. So having exactly the same code, but a fresh storyboard, makes me think it is some bug.

推荐答案

我找到了奇怪行为的原因.它需要对我们如何构建应用程序以了解其方式和原因进行一些解释.

I found the reason for the weird behaviour. It needs a little explanation on how we build our apps to understand the hows and whys.

首先,我们没有大的ViewController,而是倾向于将它们分成较小的块.这样,我们总是知道业务逻辑"在哪里,在哪里找到数据源,渠道和行动等等.一个典型的TableViewController是这样制作的:

First of all, instead of having big ViewControllers, we tend to split them into smaller chunks. This way, we always know where the "business logic" is, where to find the data source, outlets and actions, and so on. A typical TableViewController is made like this:

SampleTVC.swift

class SampleTableViewController: UITableViewController {
    @IBOutlet var someLabel: UILabel!
    @IBOutlet var someButton: UIButton!

    @IBAction func unwindHere(_ segue: UIStoryBoardSegue) {
        doSomething()
    }

}

SampleDelegate + DataSource.swift

extension SampleTableViewController {
    override func numberOfSections(in tableView: UITableView) -> Int
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
}

SampleFetchedResultsController.swift

extension SampleTableViewController: NSFetchedResultsControllerDelegate {
    var fetchedResultsController: NSFetchedResultsController<Item>
    func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>)
    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType)
    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?)
    func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>)
}

我在这里尝试将代码与由这些较小的位组成的TVC连接起来,并且没有办法弹出倒带序列.

I tried here to connect up the code with a TVC made up of these smaller bits, and no way, no rewind segue pops up.

因此,将所有扩展名与SampleTableViewController放在同一文件中,仍然无法使用.

So, putting all the extensions in the same file as the SampleTableViewController, it would still not work.

解决方案是删除所有扩展,并将所有功能放入类本身,然后按预期方式工作.这没有多大意义,显然是一个错误.

The solution was to remove all the extensions, and put all functions into the class itself, then it worked as it should. It does not make much sense, it's clearly a bug.

这篇关于Xcode 8.1出现问题并解散的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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