按钮操作后显示结果到表格视图单元格
Posted
技术标签:
【中文标题】按钮操作后显示结果到表格视图单元格【英文标题】: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
?
【问题讨论】:
【参考方案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 如果答案解决了您的问题,请不要忘记接受它(绿色勾号)。以上是关于按钮操作后显示结果到表格视图单元格的主要内容,如果未能解决你的问题,请参考以下文章