当从tableview中选择一行时,我正在将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]))
}
问题是我得到了:
在loadView()的第1行初始化注释textview时出现主题1:EXC_BAD_ACCESS ....'
错误。
通过调试,我注意到loadMethod()被反复调用,最终应用程序内存不足,因此出错。
知道为什么会连续调用loadView()?
由于
答案 0 :(得分:1)
忘记调用super.loadView();