从导航栏按钮项目中隐藏或删除特定项目,Swift 4

Hide or remove specific item from navigation bar button items, Swift 4

从故事板提供的导航栏 UIBarButtonItem 中隐藏或删除特定按钮项。

例如,右侧导航栏项目我已经从故事板中添加了 3 UIBarButtonItem,如 "Done"、"Cancel"、"next",现在我想删除或隐藏 "Cancel" 根据用户登录以编程方式从导航栏中删除按钮,那么我能为这个问题做些什么呢?

试试这个:

self.navigationItem.rightBarButtonItems?.remove(at: [indexOfButton])

[indexOfButton] 应该是按钮在 rightBarButtonItems 数组中的索引。