arrays - Swift 无法在元组数组中插入 int 值

标签 arrays swift xcode int tuples

我正在尝试将一个 int 值存储在一个元组数组中。 该数组具有以下格式:

var array: [(object1:Object1,object2:Object2,number:Int)]

我有一个表格 View ,其单元格内有按钮和文本字段。 在一个按钮中,我使用操作表字符串选择器为 textFields 赋值。

 func buttonPressed(){
let cell = button.superview?.superview? as? CustomCellClass

//i use a string picker to fill the JVFLoatLabeledTextField
// then i acces link the arrays, index to the current cell


let currentIndex = tableView.indexPath(for: cell)

 array[currentIndex.row].number = Int(cell.textfield.text!)!

 //i also insert the objects in the array, but they work fine

}

但是当我尝试访问来自不同单元格的所有存储数据时 像这样:

    for tuple in array {

print(tuple.object1.name)
print(tuple.object2.name)
print(tuple.number)

}

输出将是:object1.name, object2.name, 0 .... 每个 tuple.number 的值为 0。

如果有人提出任何建议,我将不胜感激......

最佳答案

为了缩小问题范围,我会尝试:

数组[currentIndex.row].number = currentIndex.row

如果您在遍历数组时获得预期结果,则表明问题不在于元组数组。检查从表达式返回的值

Int(cell.textfield.text!)!

关于arrays - Swift 无法在元组数组中插入 int 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51591676/

相关文章:

swift - 如何阻止 Swift 中 UIScrollView 的垂直滑动移动?

swift - 多个 SKLightNode 不能一起工作

ios - 从 objC 访问 swift 属性

ios - 从 View Controller 调用应用程序委托(delegate)方法

ios - 只能通过wifi连接到CloudKit的公共(public)容器,但不能通过蜂窝连接

ios - Cocoapods 框架无法在另一个 Cocoapods 框架中找到文件

c# 将锯齿状数组复制到字符串

php - 如何比较两个数组的相似性?

python - numpy array 每个元素与矩阵相乘

当输入负数时,Java 找到最小的数字会出现困惑