import UIKit
class MasterViewController: UITableViewController {
var objects:NSMutableArray!
1 var bl = NoteBL()
var detailViewController:DetailViewController? = nil
override func awakeFromNib() {
super.awakeFromNib()
if UIDevice.currentDevice().userInterfaceIdiom == .Pad{
self.clearsSelectionOnViewWillAppear = false
self.preferredContentSize = CGSize(width: 320.0, height: 600.0)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail"{
if let indexPath = self.tableView.indexPathForSelectedRow(){
let object = objects[indexPath.row] as Note
let controller = (segue.destinationViewController as UINavigationController).topViewController as DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
func reloadView(notification:NSNotification){
var resList = notification.object as NSMutableArray
self.objects = resList
self.tableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = self.editButtonItem()
if let split = self.splitViewController{
let controllers = split.viewControllers
self.detailViewController = controllers[controllers.count-1].topViewController as? DetailViewController
}
2 self.objects = self.bl.findAllNote()//如果1没有实例化,这一句就会报错,显示空指针;我的错误是:第一句我写成var bl:NoteBL;
应该写成var bl = NoteBL()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reloadView:", name:"reloadViewNotification" , object: nil)
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}