- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我在 View Controller 的顶部添加了一个导航栏。我试图根据条件控制按钮是否可见,但添加按钮时遇到问题。到目前为止,我有,
var addButton: UIBarButtonItem = UIBarButtonItem(title: "test", style: .done, target: self, action: #selector(addTapped))
override func viewDidLoad() {
super.viewDidLoad()
let boool = true
if boool {
self.navigationItem.rightBarButtonItem = self.addButton
}
else {
self.navigationItem.rightBarButtonItem = nil
}
}
func addTapped(sender: AnyObject) {
print("hjxdbsdhjbv")
}
我认为它不能正常工作,因为我在 VC 中添加了一个导航栏,而不是使用导航 Controller 并在那里使用该栏。我想知道是否有办法使用这个导航栏。
最佳答案
很简单。将这行代码放到 viewDidLoad
中:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "test", style: .done, target: self, action: #selector(addTapped))
针对 Swift 4 更新 或更高版本:
自定义函数:
@objc func action(sender: UIBarButtonItem) {
// Function body goes here
}
(自定义)右栏按钮项目:
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "some_text", style: .done, target: self, action: #selector(self.action(sender:)))
(自定义)左栏按钮项目:
self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "some_text", style: .done, target: self, action: #selector(self.action(sender:)))
您还可以添加系统栏按钮项目,如下所示:UIBarButtonItem.SystemItem
为栏按钮项目定义系统提供的图像:.add、.done、.cancel 、.edit、.save、.compose、.reply、.organize 等等。
(系统)右栏按钮项:
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonItem.SystemItem.add, target: self, action: #selector(self.action(sender:)))
(系统)左栏按钮项:
self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonItem.SystemItem.add, target: self, action: #selector(self.action(sender:)))
关于ios - Swift 3.0 向导航栏添加一个右键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45069477/
我有点困惑。在 : http://delphi.about.com/od/objectpascalide/l/blvkc.htm 它说“Space”的正确键是#20。试过了,但行不通。但是,将其替换为
我有一个 input 的 type="submit" 并且我希望当我点击(右键或左键点击)它时这个元素周围没有蓝色边框。 我在下面的chrome浏览器中添加了OK模式和not OK模式的图片: OK模
我想在右键单击选项卡标题时显示上下文菜单条。 但是,我没有找到检测选项卡标题点击的方法。 有人知道如何做到这一点吗? 最佳答案 Private Sub tab1_MouseClick(sender A
我对编程还很陌生,正在尝试制作扫雷 GUI。游戏完美地右键单击 JToggleButton,在按钮上显示了一个代表炸弹的“B”,但是当我在鼠标监听器中用 setIcon() 替换 setText()
我正在尝试将一个按钮 float 到卡片的右侧。我希望它出现在右下角。 当我正确使用 float 时。它出现在父 div 之外,有没有办法正确定位它?
我正在使用 Struts2 标签和下面的代码使用 JS 计算并检查/验证在文本字段中输入的值。 它还会更新在 textfield 中输入的总数列表,这些由 onblur 处理和 onkeydown事件
我是一名优秀的程序员,十分优秀!