ios NSIndexPath 初始化在 Swift3 中有何变化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38382481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How has the NSIndexPath initialization changed in Swift3?
提问by Garry Pettet
I'm trying to follow along with Apple's Start Developing iOS Apps (Swift) tutorialand have almost completed it. I have had to amend several parts of the tutorial as I'm using Xcode 8 (which I think uses Swift 3 instead of Swift 2). However, I am running into the following compiler error and I don't know why:
我正在尝试按照 Apple 的开始开发 iOS 应用程序 (Swift) 教程进行操作,并且几乎已完成。由于我使用的是 Xcode 8(我认为它使用 Swift 3 而不是 Swift 2),我不得不修改教程的几个部分。但是,我遇到了以下编译器错误,我不知道为什么:
Argument labels (forRow:, inSection) do not match any available overloads
Argument labels (forRow:, inSection) do not match any available overloads
in the following function:
在以下功能中:
@IBAction func unwindToMealList(sender: UIStoryboardSegue) {
if let sourceViewController = sender.sourceViewController as? MealViewController, meal = sourceViewController.meal {
// Add a new meal
let newIndexPath = NSIndexPath(forRow: meals.count, inSection: 0)
meals.append(meal)
tableView.insertRows(at: newIndexPath, with: .bottom)
}
}
I'm guessing that there is a different initialiser for NSIndexPath that's changed in Swift 3 but I can't find it. Am I doing something wrong?
我猜测 NSIndexPath 有一个不同的初始化器,它在 Swift 3 中发生了变化,但我找不到它。难道我做错了什么?
Thanks,
谢谢,
回答by iOSGeek
NSIndexPath
has been changed to IndexPath
NSIndexPath
已更改为 IndexPath
try IndexPath(row: Int, section: Int)
尝试 IndexPath(row: Int, section: Int)