我的应用程序中只有几个 ViewController,并且所有 ViewController 都有菜单按钮。当按下此按钮时 - 菜单 ViewController 将打开。
我想用红点标记菜单按钮,显示一些新内容可用,用户需要按菜单按钮才能查看哪个菜单项标记有此点。
由于我的所有按钮都是相互独立的 - 我认为我需要这样解决它
- 在每个菜单按钮上添加红点图像
- 默认隐藏这个点
- 打开每个 ViewController 时 - 我应该检查 - 是否有任何新项目可用,并将该红点图像的 isHidden 属性切换为 false。
但也许有一些更优雅的方式?
最佳答案
当有新内容可用时使用 NotificationCenter 通知 ui
在菜单 View Controller 类中:
//put this in viewDidLoad
NotificationCenter.default.addObserver(self.selector : #selector(menuviewcontroller.refresh(_:)),name:NSNotification.Name(rawValue:"showRedBtn"),object : nill)
//create function refresh
func refresh(_ notification : Notification)
{
//make the red dot visible
}
创建类监听是否添加了任何内容,并在通过这行代码添加的情况下调用委托(delegate)
NotificationCenter.default.post(name : Notification.Name("showRedBtn"),object : nil , userInfo : nil)
希望对你有帮助
关于ios - 有新项目时标记移动应用程序菜单按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42694334/