Ios Swift-嵌套导航控制器缺失“;编辑";按钮

Ios Swift-嵌套导航控制器缺失“;编辑";按钮,ios,swift,uinavigationcontroller,uinavigationbar,segue,Ios,Swift,Uinavigationcontroller,Uinavigationbar,Segue,我有一个图书馆应用程序,当你点击每个图书馆时,它会调出一个书架列表,一旦点击,就会调出每个书架上的书籍列表。我在导航栏中仅在显示书籍列表的视图上添加“+”以添加书籍时遇到问题。我尝试过以编程方式添加它,也尝试过使用故事板添加它,但是,尽管应用程序构建和运行正常,但按钮始终没有出现。任何与此相关的建议都将非常棒 以下是我的bookTableViewController代码: import UIKit class bookTableViewController: UITableViewContro

我有一个图书馆应用程序,当你点击每个图书馆时,它会调出一个书架列表,一旦点击,就会调出每个书架上的书籍列表。我在导航栏中仅在显示书籍列表的视图上添加“+”以添加书籍时遇到问题。我尝试过以编程方式添加它,也尝试过使用故事板添加它,但是,尽管应用程序构建和运行正常,但按钮始终没有出现。任何与此相关的建议都将非常棒

以下是我的bookTableViewController代码:

import UIKit

class bookTableViewController: UITableViewController {

@IBOutlet var addBookButton: UIBarButtonItem!

var currentShelf = Shelf()

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.title = "Shelf"

    navigationItem.rightBarButtonItem?.title = "Add"

    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return currentShelf.allBooksOnShelf.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    cell.textLabel.text = currentShelf.allBooksOnShelf[indexPath.row].bookName

    return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    if currentShelf.allBooksOnShelf[indexPath.row].hasBeenRead == false{
        currentShelf.allBooksOnShelf[indexPath.row].hasBeenRead = true
    var alert = UIAlertController(title: "Read Book", message: "Thanks For Reading!", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)

    }
    else{
        currentShelf.allBooksOnShelf[indexPath.row].hasBeenRead = false
        var alert = UIAlertController(title: "Read Book", message: "You Just UnRead A Book...", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)

    }

}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    if editingStyle == .Delete {

        // Delete the row from the data source
        currentShelf.allBooksOnShelf.removeAtIndex(indexPath.row)
        self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

    } else if editingStyle == .Insert {
        // Create a new instance of the appropriate class, insert it into the array, and add a        new row to the table view
    }
    }


 }
下面是我用来从Shelf Table View控制器推送到这个TableVC的代码:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let vc = bookTableViewController()

    vc.currentShelf = currentLibrary.allShelves[indexPath.row]

    navigationController?.pushViewController(vc, animated: true)


}

谢谢

这是因为您需要创建一个
rightBarButtonItem
,而不仅仅是设置标题。试试这个:

var barButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: @"addTapped:")
self.navigationItem.rightBarButtonItem = barButton