我在右边有一个简单的+按钮,可以将行添加到我的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)

为什么会这样?

最佳答案

尝试:

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

关于swift - BarButtonItem没有出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38705442/

10-17 00:00