【发布时间】:2017-09-02 11:24:36
【问题描述】:
我想在数组中保存值并检查数组中的值是否存在。
我使用这个代码:
保存价值
var index = 0
var array = [Int]()
self.array.append(self.index)
但是如何检查数组中的值是否存在并在控制台中显示数组中的数字值?
示例:
检查值
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
if "values for array exist" {
//show text for all row numbers in the array
}
}
将值保存在数组中
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
index = indexPath.row
self.array.append(self.index.row) //save row number
}
【问题讨论】:
-
“数组中的值 = true”和“显示下一个代码”是什么意思?
-
谁赞成这个...问题??
-
@Sweeper 我想在数组中添加值。检查数组中的值是否存在。如果数组中的值存在,我应该显示:
// my next code. -
“代码”是什么意思?
-
@MoeAbdul-Hameed 任何代码,例如在控制台中显示数组中的数字值