swift - 如何在 swift 3 中从数组中查找特定位置对象

标签 swift uitableview

我在下面的 FinalArray 数组中插入了一些对象。现在我想将它们显示在 tableList 中,以便我需要找到每个位置对象。我该如何写该声明,有人可以帮助我吗?

我的代码:-

 var forcast:Forecast?
 var finalArray = [Forecast]()

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell  {
     forcast = finalArray.index(indexpath);
    }

最佳答案

NSIndexPath有部分和行

您需要根据 indexPath.sectionindexPath.row 进行访问,具体取决于您如何使用 tableView datasource 对 tableView 上的数据进行分类。

例如:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell  {
     forcast = finalArray.index(indexpath.row);//
}

关于swift - 如何在 swift 3 中从数组中查找特定位置对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45050568/

相关文章:

ios - Swift 和 HealthKit : type of expression too ambiguous without more context

ios - Swift 3.2 中任何调用函数 append.contentsOf 语法错误的数组

ios - 如何快速设置文本字段的布局边距?

swift - 是否有任何解决方法可以将存储的属性快速放入扩展中?

ios - ios的折叠工具栏布局

ios - 快速刷新表格 View 单元格数据

ios - 单击自定义 UITableViewCell 上的按钮会抛出 EXC_BAD_ACCESS

iphone - 如何使 UITableViewCell 上的滑动删除按钮变小?

swift - 自定义单元格中的 didSelectRowAt 不执行任何操作

macos - 如何制作一个 MenuBar 应用程序(使用 Swift),它不仅包含菜单项列表?