如何在表视图中获取值ForRowAt indexPath?

时间:2018-06-22 10:35:09

标签: ios arrays swift uitableview

我在以下两个数组之间建立关联并获得所需的输出时遇到问题:

场景:

  1. 我有2个数组,如下所示:

sectionArray

[["mbsdcie6_2_1": Incomer 132 KV Parameters, "mbsdcie6_2_2": <__NSCFArray 0x604000115180>(
3,
6,
4,
5,
8,
30,
31,
7,
18,
29,
1
)
], ["mbsdcie6_2_1": SMS2 Parameters, "mbsdcie6_2_2": <__NSCFArray 0x6040000a3f60>(
9,
10,
11,
12,
13,
14
)
], ["mbsdcie6_2_1": SMS 1 Parameters, "mbsdcie6_2_2": <__NSCFArray 0x604000267880>(
15,
17
)
]]

ParamName

["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."]

问题:

  • 现在我希望从 sectionArray 中的“ mbsdcie6_2_2” 索引从 paramName 中获取值tableView 方法 cellForRowAt indexPath

例如:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
    {
    let cell = tableView.dequeueReusableCell(withIdentifier: "DataMonitorCell", for: indexPath) as! DataMonitorCell

    cell.lblParameter.text = "Set MD" // value as per the index value 3 of key "mbsdcie6_2_2" from sectionArray

return cell
    }

编辑1:

  • 这是我检索sectionArray的方式:

    var sectionArray =字典

    覆盖func viewWillAppear(_动画:Bool){         sectionArray = kUserDefault.array(forKey:kHeadersArray)为! [字典]

        print(sectionArray)
    }
    
  • 这是我检索ParamName的方式

    ///在另一个ViewController中,我这样检索它:

    var paramName =字符串

    覆盖func viewWillAppear(_动画:布尔){

        paramName = kUserDefault.value(forKey: kParameterNameArray) as! [String]
    
        print(paramName)
    }
    

我尝试了很多方法,但是对我来说似乎很复杂。任何帮助将不胜感激,谢谢!

0 个答案:

没有答案