2015-12-16 21 views
-1

當我提出我的UITableViewController從modaly的其他地方的應用程序,我得到一個錯誤:NSException錯誤從其他地方呈現的UITableViewController當模態

libc++abi.dylib: terminating with uncaught exception of type NSException

相同的代碼工作從蘋果默認的項目是什麼問題?

import UIKit 

class SettingViewController: UITableViewController { 
    let fruits = ["Apple", "Orange", "Peach"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 

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

    override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated) 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    // MARK: - Table view data source 

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return fruits.count 
    } 

    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
     return "Section \(section)" 
    } 

    override func tableView(tableView: UITableView, 
     cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

      let cell = tableView.dequeueReusableCellWithIdentifier("TextCell", forIndexPath: indexPath) 
      let fruit = fruits[indexPath.row] 
      cell.textLabel!.text = "\(indexPath.section).\(indexPath.row): \(fruit)" 

      return cell 
    } 
} 
+1

在[異常斷點]把(https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint .html)查看它崩潰的位置。我懷疑你沒有創建一個標識符爲「TextCell」的單元格 – shim

+0

錯誤原因libC++ abi.dylib:終止於類型爲NSException的未捕獲異常 – David

+0

斷點在 let cell = tableView.dequeueReusableCellWithIdentifier(「reuseIdentifier 「,forIndexPath:indexPath) – David

回答

0

在viewDidLoad中()我添加

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier") 
+0

我懷疑這確實解決了OP的問題,所以它確實提供了一個問題的答案。但是,代碼中的reuseIdentifier是「TextCell」,在這裏您正在註冊一個標識爲「reuseIdentifier」的單元。 – shim

相關問題