【问题标题】:Show result after button action to table view cell按钮操作后显示结果到表格视图单元格
【发布时间】:2018-04-12 09:03:16
【问题描述】:
var monthsOfNonWorking = ["1. mēnesis","2. mēnesis","3. mēnesis","4. mēnesis","5. mēnesis","6. mēnesis","7. mēnesis","8. mēnesis","9. mēnesis",]        

@IBAction func nonWorkingAllowanceCalculate(_ sender: Any) {

    var firstThreeMonths :Double
    var secondThreeMonths :Double
    var LastThreeMonths :Double

    let bezdarbienieka_alga = Double(bezd_alga.text!)


    if (staza_masiva_lasisana == 0) {

        firstThreeMonths = Double(bezdarbienieka_alga! / 2)

        secondThreeMonths = Double(firstThreeMonths / 2)

        LastThreeMonths = Double(bezdarbienieka_alga! / 1.6 - secondThreeMonths) }}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MonthTableViewCell

    switch indexPath.row {
    case 0: cell.nonWorkingAllowance?.text = String()

    }

    cell.monthLabel?.text = monthsOfNonWorking[indexPath.row]

    return cell
}

如何在使用按钮操作计算后在表格视图单元格上显示结果? 比如我想在tableViewCell上显示数据firstThreeMonths

【问题讨论】:

    标签: ios swift xcode uitableview tableview


    【解决方案1】:

    只需在按钮操作的末尾添加tableView.reloadData()

    @IBAction func nonWorkingAllowanceCalculate(_ sender: Any) {
    
    var firstThreeMonths :Double
    var secondThreeMonths :Double
    var LastThreeMonths :Double
    
    let bezdarbienieka_alga = Double(bezd_alga.text!)
    
    
    if (staza_masiva_lasisana == 0) {
    
        firstThreeMonths = Double(bezdarbienieka_alga! / 2)
    
        secondThreeMonths = Double(firstThreeMonths / 2)
    
        LastThreeMonths = Double(bezdarbienieka_alga! / 1.6 - secondThreeMonths)
     }
    
     tableView.reloadData()
    
    }
    

    【讨论】:

    • 谢谢,也许这个问题不是那么难,但我正在学习。谢谢。
    • @user3465573 如果答案解决了您的问题,请不要忘记接受它(绿色勾号)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    相关资源
    最近更新 更多