Ios 将(Int,String)转换为字符串以打印数组

Ios 将(Int,String)转换为字符串以打印数组,ios,swift,string,Ios,Swift,String,我试图调用要在表视图中打印的数组。唯一的问题是[Int,String]类型的数组numbersWithCreationDateis。我怎样才能让有创意的人在这里工作。这样就可以打印文本了。它说这不起作用,因为它只能接受一个字符串 cell.textLabel?.text = numbersWithCreationDates[indexPath.row] 获取元组: // Get the tupel at index of the current row let tupel = numbe

我试图调用要在表视图中打印的数组。唯一的问题是[Int,String]类型的数组numbersWithCreationDateis。我怎样才能让有创意的人在这里工作。这样就可以打印文本了。它说这不起作用,因为它只能接受一个字符串

   cell.textLabel?.text = numbersWithCreationDates[indexPath.row]
获取元组:

// Get the tupel at index of the current row
let tupel = numbersWithCreationDates[indexPath.row] 
获取字符串:

// Get the second value of the tupel, the string value ...
let string = tupel.1
cell.textLabel?.text = string

您需要将其转换为字符串数据类型

试试这个:

cell.textLabel?.text=StringNumberWithCreationDates[indexPath.row]

说明:


UITableViewCell由UILabel组成。UILabel的text属性需要一个字符串,而您正在传递一个数字或Int。当您调用字符串初始值设定项时,它会将此数字转换为UILabel的text属性所需的字符串。

如果您只想使用元组的一部分,或者想以某种方式格式化元组,可以使用.0和.1分隔这两部分。例如:

cell.textLabel?.text = "Number: \(numbersWithCreationDates[indexPath.row].0) Date: 
\(numbersWithCreationDates[indexPath.row].1)"

请显示int,String类型数组的声明。这是否有助于var numbersWithCreationDates=[int,String],因此您有一个元组数组。您应该编辑您的问题以清楚地说明这一点,并将注释中的代码直接放入您的问题中。错误消息“未来状态”无法使用“int,String”类型的参数列表调用“String”类型的初始值设定项,并相应地更新了答案。这将获取数组中的所有条目。它是元组。1如果在numberOfRowsInSection中返回NumberWithCreationDates.cout,则返回yes。错误消息:状态无法使用“int,String”类型的参数列表调用“String”类型的初始值设定项