【发布时间】:2018-06-22 12:44:44
【问题描述】:
长期以来,我一直面临着这个问题。
- 问题:
我需要根据 tableView 中以下数组的索引获取值。
indexArray = [3, 6, 4, 5, 8, 30, 31, 7, 18, 29, 1]
paramNameArray = ["Date", "Sync Time", "UUC2T7", "Set MD", "Total KVA", "Total KW", "Running MD", "SMS 1 KW", "P.F.", "ET-5 KW", "ET-3_4 KW", "ET- 6_7 KW", "ABP-1 KW", "ABP-1A KW", "ABP-2 KW", "G-22 KW", "UUC36T37", "G-23 KW", "WRM KW", "Total KWH", "Total KVAH", "ET-5 KWH", "ET-3_4 KWH", "ET-6_7 KWH", "ABP-1 KWH", "ABP-1A KWH", "ABP-2 KWH", "SMS 1 KWH", "UUC60T73", "PLC Time", "Voltage", "Current", "Load Factor", "Avg. P.F."]
问题:
- 现在在我的 tableView 的 cellForRowAt indexPath 中,我需要在 indexPath 0 处“设置 MD”值(需要根据 indexArray 的索引值)
这样对于tableView的每一行,我都需要根据indexArray的索引值。
例如:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
(at 0th Index) cell.lblParameter.text = "Set MD" // value from paramNameArray as per indexArray's index(3)
(at 1st Index) cell.lblParameter.text = "Running MD" // value from paramNameArray as per indexArray's index(6)
// And so on...
return cell
}
非常感谢您的帮助,谢谢! :)
【问题讨论】:
-
cell.lblParameter.text = paramNameArray[indexArray[indexPath.row]] -
@vacawama,我不敢相信它这么简单。非常感谢你!
-
你应该重新考虑你的数据结构。这有一种代码味道,你最终会得到一个崩溃的应用程序。
-
@AshleyMills,对不起我的英语。但我听不懂你说的。
-
祝你好运!
标签: ios arrays swift uitableview