ios - 数组没有 objectAtindex 成员

标签 ios xcode uitableview swift

我正在构建一个简单的 Swift CoreData TableView 应用程序。我已成功将数据保存到数据库并在 TableView 中重新加载数据。接下来我要做的是编辑这些数据。通过点击表格单元格/行,我将通过将详细信息传递给另一个 View Controller 并填充一些文本字段来编辑数据。但是我在选择正确的数组索引时遇到了麻烦。在 Objective-C 中,使用 NSMUtableArray 会更容易(我认为)。

我的数组是这样定义的

var myList: Array<AnyObject> = []
适合executeFetchRequest()返回类型的数组

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {

    if segue.identifier == "Edit" {
       var data: NSManagedObject = (myList.objectAtIndex(self.tableView.indexPathForSelectedRow().row))
    }
}

在 Swift 中,objectAtIndex 是什么? ? (如果这是正确的问题)

这是我得到的错误: enter image description here

最佳答案

使用下标语法,在数组名称后立即在方括号内传递要检索的值的索引:

myList[self.tableView.indexPathForSelectedRow().row]

关于ios - 数组没有 objectAtindex 成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24341093/

相关文章:

iphone - 使用 json-framework 提取 iphone 应用程序

xcode - 您可以在 Xcode 4.3 的 .xcconfig 文件中设置特定于架构的build设置吗?

iphone - 错误 : Warning: The Copy Bundle Resources build phase contains this target's Info. plist 文件 'UserDefinedLocalization-Info.plist'

ios - TableView 在单元格上滚动时创建多个accessoryType

iphone - Xcode "Use of undeclared identifier"

ios - tableView 的 UIRefreshControl 滚动时覆盖第一个单元格

ios - 如何将 UITextField 值转换为 NSNumber?

iphone - 为 iPhone 5 分辨率调整布局

iphone - 如何使用 ELCImagePickerController 和 ALAssetsLibrary 在照片库中选择多个图像?

ios - 查找当前位置与另一个位置之间的距离 (Swift 5)