BarButtonItem没有出现

时间:2016-08-01 18:11:25

标签: swift uibarbuttonitem

我右侧有一个简单的+按钮,可以在tableView中添加行,但按钮没有出现。这就是我实现它的方式

    let AddButton = UIButton()
    AddButton.setTitle("+", forState: .Normal)
    let AddView = UIBarButtonItem(customView: AddButton)
    self.navigationItem.rightBarButtonItem = AddView
            AddButton.addTarget(self, action: #selector(self.addRow), forControlEvents: UIControlEvents.TouchUpInside)

注意,我使用与我的汉堡包按钮完全相同的实现方式。这是工作汉堡包按钮实现

    let navicon = UIButton(type: UIButtonType.System)
    navicon.setImage(defaultMenuImage(), forState: UIControlState.Normal)
    navicon.frame = CGRectMake(0, 0, 30, 30)
    let menu = UIBarButtonItem(customView: navicon)
    self.navigationItem.leftBarButtonItem = menu
    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    navicon.addTarget(self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)), forControlEvents: .TouchUpInside)

为什么会这样?

1 个答案:

答案 0 :(得分:0)

尝试:

let AddButton = UIButton(type: .Custom)
AddButton.frame = CGRectMake(0, 0, 44, 44)