0
我有一个图书馆应用程序,当你点击每个图书馆时,它会打开一个书架列表,一旦点击,然后拉出书架列表。我遇到了问题,只在显示书籍列表的视图上的导航栏中添加“+”以添加图书。我曾尝试以编程方式将其添加到故事板中,但尽管应用程序构建并正常运行,但该按钮从未出现。任何意见,这将是真棒!Swift - 嵌套导航控制器缺少“编辑”按钮
下面是我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代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vc = bookTableViewController()
vc.currentShelf = currentLibrary.allShelves[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
感谢
完美!这非常感谢。 – awallraff 2014-11-14 18:34:50