【发布时间】:2015-11-19 09:09:30
【问题描述】:
我正在尝试向导航项添加三个按钮,我编写了以下代码:
let customNavigationItemView : UIView = UIView()
let trendbutton : UIButton = UIButton(type: .Custom)
size = myString.sizeWithAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14.0)])
size.width = size.width * 1.5
nearbybutton.frame.size = size
...
let nearbybutton : UIButton = UIButton(type: .Custom)
...
let squarebutton : UIButton = UIButton(type: .Custom)
...
trendbutton.frame.origin = CGPointMake(-trendbutton.frame.size.width - nearbybutton.frame.size.width / 2, 0)
...
customNavigationItemView.addSubview(trendbutton)
customNavigationItemView.addSubview(nearbybutton)
customNavigationItemView.addSubview(squarebutton)
self.navigationItem.titleView = customNavigationItemView
trendbutton.addTarget(self, action: "circleNavigationBar_trendButton_clickUp:", forControlEvents: .TouchUpInside)
nearbybutton.addTarget(self, action: "circleNavigationBar_nearbyButton_clickUp:", forControlEvents: .TouchUpInside)
squarebutton.addTarget(self, action: "circleNavigationBar_squareButton_clickUp:", forControlEvents: .TouchUpInside)
还有这个:
func circleNavigationBar_trendButton_clickUp(sender : UIButton) {
print("trend click")
}
但是当我单击导航项中的按钮时,什么也不打印。 谁能告诉我原因?还是谢谢大家。
【问题讨论】:
标签: uinavigationcontroller uinavigationbar swift2 uinavigationitem