2014-11-14 4 views
0

У меня есть приложение для библиотеки, которое, щелкая каждую библиотеку, вытаскивает список полки, которые после щелчка вытаскивают список книг на каждой полке. У меня возникают проблемы с установкой «+» в навигационной панели только на просмотр, показывающий список книг, которые можно добавить в книгу. Я попытался добавить его программно, а также в раскадровку, но, хотя приложение строит и работает правильно, кнопка просто не появляется. Любые советы с этим были бы замечательными!Быстрое вложение контроллера навигации отсутствует кнопка «edit»

ниже мой 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 
    } 
    } 


} 

Вот код, я использую, чтобы подтолкнуть к этому TableVC из таблицы View Controller Shelf:

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

    let vc = bookTableViewController() 

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

    navigationController?.pushViewController(vc, animated: true) 


} 

Благодаря

ответ

0

Это потому, что вы необходимо создать rightBarButtonItem, а не просто установить заголовок. Попробуйте следующее:

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

безупречный! это произвело большое спасибо. – awallraff

Смежные вопросы