ios - How to update my xib labels from another view controller
问题描述
I am trying to figure out how to update my xib labels when a button is pressed on another view controller
Currently I have a xib swift file that contains all my labels
var habit: Habit? {
didSet {
self.updateUI()
}
}
func updateUI() {
habitXibName?.text = habit?.title
totalProgress?.text = habit?.totalCount
progressBarXib?.progress = habit?.progress ?? 0.0
userProgress?.text = String(habit?.userCount ?? 0)
}
In another view controller I have the following code
do {
try realm.write {
if selectedHabit!.userCount == (Int(selectedHabit!.totalCount )! - 1) {
selectedHabit!.userCount += 1
habitcell.habitXibName?.text = String(selectedHabit?.userCount ?? 0)
view.addSubview(confettiView)
confettiView.startConfetti()
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.confettiView.stopConfetti()
}
} else {
selectedHabit!.userCount += 1
}
}
} catch {
print(error)
}
what I want to happen is to update my xib label to the selectedHabit?.userCount
habitcell.habitXibName?.text = String(selectedHabit?.userCount ?? 0)
However, my habitcell.habitXibName returns nil and I'm not sure why. Thanks for everything!
解决方案
推荐阅读
- javascript - 为什么这段代码不会显示hello world?它说 text.content 为 null
- marklogic - cts.estimate 显示错误的文档计数
- python - 使用 AWS CDK for python 创建 AWS 网络负载均衡器时无法传递 ec2-instance 详细信息
- html - 每个索引上的 SCSS for 循环 x 次
- vector - 沿向上向量的最高点
- twitter - 如何通过 Twitter API 计算推文数量
- reactjs - 反应警告消息“将箭头函数分配给变量”
- r - 如何通过点图绘制二进制数据?
- javascript - 如何使用正则表达式从状态为“通知”或“无库存”的字符串中删除项目
- javascript - 如何在 jquery javascript 中从数组中创建逗号分隔的字符串