我实现了一个注释中心每当你点击一个特定的表视图单元在另一个内部执行该通知视图控制器,在这个例子中,另一个视图控制器背景颜色变成粉红色,效果很好,但我的问题是,如何保存粉红色的状态在里面是相同的。视图控制器使用用户缺陷?
为了更好地澄清这一点:
视图控制器#2包含当按下操作时执行操作的TableViewCell
视图控制器#1是颜色变化为粉红色的视图。
我想实现什么?
保存粉红色的状态视图控制器#1使用用户缺陷
视图控制器#1代码
-视图DidLoad
override func viewDidLoad()
{
NotificationCenter.default.addObserver(self, selector: #selector(BrandTableViewController.testNotifcation(notification:)), name:NSNotification.Name(rawValue: "refresh"), object: nil);
}
-TestNotification功能
@objc func testNotifcation(notification: NSNotification) {
table.backgroundColor = UIColor.systemPink
print("This is a message to say it is working")
}
视图控制器#2代码
罗瓦特
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0
{
if traitCollection.userInterfaceStyle == .light
{
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "refresh"), object: nil, userInfo: nil)
self.dismiss(animated: true, completion: nil)
}
else if traitCollection.userInterfaceStyle == .dark
{
...
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。