Dismiss a Modal UIViewController created in Interface Builder

There are a number of posts on this subject on Stack. They involve re-instantiating (this seems slower to me) or yanking the view from a UIButton (this feels dirty).

I’d rather just update the UIBarButtonItem that I already have:


All I needed to do, was attach the appropriate target and action to the UIBarButtonItem:

class SettingsTableViewController : UITableViewController {

    @IBOutlet weak var doneBarButton: UIBarButtonItem!

    init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)

    override func viewDidLoad() {

        doneBarButton.target = self
        doneBarButton.action = "donePressed:"

    @IBAction func donePressed(b:UIBarButtonItem) {
        self.dismissViewControllerAnimated(true, completion: {})