码迷,mamicode.com
首页 > 其他好文 > 详细

没有实例化报错的案例

时间:2015-09-24 10:57:24      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

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
           
        }
       
     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()
    }

没有实例化报错的案例

标签:

原文地址:http://www.cnblogs.com/wenios/p/4834452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!