gpt4 book ai didi

ios - Xcode 8.1 和 unwind segues 有问题

转载 作者:搜寻专家 更新时间:2023-10-31 08:31:45 25 4
gpt4 key购买 nike

我无法放松 segue 以使用最新的 Xcode 8.1 GM。我只是想知道我是唯一一个,还是其他人正在经历同样的事情。我已经像以前一样设置了 View Controller ,它在 Xcode 8.0 中工作,但现在我没有运气了。试图清洁等等,但没有任何帮助。我希望其他人也可以在我提交雷达之前对其进行测试...

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

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

我也试过不加下划线,但没有用。设置它时,应该能够 ctrl 从文件所有者拖动到退出,并启动 unwind segues: No unwind segue showing up here...所以要么我做的完全错了(我不这么认为,它以前工作得很好),要么 Xcode 8.1

中有一个错误

我尝试在一个新项目中做同样的事情,然后它工作正常。所以我猜我的项目或 Storyboard文件有问题。

更新

由于 Storyboard中的场景相当小,我只是将其删除,然后重新创建,对 View Controller 等使用相同的类。现在它起作用了。因此,具有完全相同的代码,但有一个全新的 Storyboard,这让我认为这是一些错误。

最佳答案

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

首先,我们倾向于将它们分成更小的 block ,而不是拥有大的 ViewController。这样,我们始终知道“业务逻辑”在哪里,在哪里可以找到数据源、导出和操作等等。一个典型的 TableViewController 是这样制作的:

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 连接起来,但没办法,没有弹出倒带转场。

因此,将所有扩展与 SampleTableViewController 放在同一个文件中,它仍然无法工作。

解决方案是删除所有扩展,并将所有函数放入类本身,然后它就可以正常工作了。这没有多大意义,这显然是一个错误。

关于ios - Xcode 8.1 和 unwind segues 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40264022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com