loadView() 抛出 EXC_BAD_ACCESS 内存错误

loadView() throwing EXC_BAD_ACCESS memory error

当从表视图中选择一行时,我将 ViewController 压入堆栈:

if let cell = tableView.cellForRowAtIndexPath(indexPath){

        let genre = cell.textLabel?.text ?? SelectGenreTableViewController.genres[0]; // nil coalsing trtary operand, if text desnt exist assign first value or static array belining to class not instance
        let vc = AddCommentsViewController();
        vc.genre = genre;
        navigationController?.pushViewController(vc, animated: true);

这个新的视图控制器视图是在 loadView() 中以编程方式构建的:

 override func loadView() {
        // pin the text voew to all sides and use dynamoc to make font size adjustable to user

        comments = UITextView(); // BAD ACCESS THROWN HERE
        comments.translatesAutoresizingMaskIntoConstraints = false;
        comments.delegate = self;
        comments.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody);
        view.addSubview(comments);



 view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[comments]|", options: .AlignAllCenterX, metrics: nil, views: ["comments": comments]))
 view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[comments]|", options: .AlignAllCenterX, metrics: nil, views: ["comments": comments]))
 }

问题是我得到一个 :

Thread 1: EXC_BAD_ACCESS ....'

在 loadView() 的第 1 行初始化注释文本视图时出错。

通过调试,我注意到 loadMethod() 被一遍又一遍地调用,最终应用程序内存不足,因此出现错误。

知道为什么会连续调用 loadView() 吗?

谢谢

忘记调用 super.loadView();