tableView.reloadData()在覆盖函数

时间:2018-02-03 11:38:26

标签: ios uitableview tableview reloaddata

在底部代码中,tableView.reloadData()在我在overriden函数中使用时工作,并且在OM_Status的didSet函数中不起作用... 有谁知道问题是什么?! OM_Status将通过 lptvc var在其他swift文件中的运行时更改... .................................................. .......................................

import UIKit

class LampPazireshTableViewController: UITableViewController {
var lampName = ["name1" , "name2" , "name3" , "name4" , "name5" , "name6" , "name7"]
var lampImage = [#imageLiteral(resourceName: "loosteroff") , #imageLiteral(resourceName: "loosteroff") , #imageLiteral(resourceName: "halojenoff") , #imageLiteral(resourceName: "halojenoff") , #imageLiteral(resourceName: "noormakhof") ,
#imageLiteral(resourceName: "noormakhof") , #imageLiteral(resourceName: "halojenoff")]
public static var lptvc = LampPazireshTableViewController()
var OMStatus : Int? {
    didSet {
        for index in 0..<lampImage.count {
            switch index {
            case 0 , 1 :
                lampImage[index] = OMStatus! & power(2, index) != 0 ? #imageLiteral(resourceName: "loosteron") : #imageLiteral(resourceName: "loosteroff")
            case 2 , 3 , 6:
                lampImage[index] = OMStatus! & power(2, index) != 0 ? #imageLiteral(resourceName: "halojenon") : #imageLiteral(resourceName: "halojenoff")
            case 4 , 5 :
                lampImage[index] = OMStatus! & power(2, index) != 0 ? #imageLiteral(resourceName: "noormakhfion") : #imageLiteral(resourceName: "noormakhof")
            default:
                break
            }
        }
        tableView.reloadData()
    }
}

func power (_ from : Int , _ to : Int) -> Int {
    var temp = from
    for _ in 0..<to {
        temp *= from
    }
    return temp
}

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 7
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "lamppaziresh", for: indexPath)
    if let finalCell = cell as? LampPazireshTableViewCell {
        finalCell.lampName.text = indexPath.row < lampName.count ? lampName[indexPath.row] : "unknown"
        finalCell.lampImage.image = indexPath.row < lampImage.count ? lampImage[indexPath.row] : nil
    }
    // Configure the cell...

    return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    communicationMethods().Send_Frame(from: 16, to: 1, with: opcodes().OM_Toggle_Output, and: [indexPath.row + 1])
    tableView.reloadData()
}

0 个答案:

没有答案