2016-09-14 40 views
1

將代碼庫從Swift 2升級到Swift 3後,我最近將我的應用從Xcode 7遷移到Xcode 8。該應用程序編譯正常,但在運行時我得到以下異常。在iOS應用運行時期間獲取NSInternalInconsistencyException

不知道這裏需要做什麼。

例外:

2016-09-14 14:00:16.098 ApplePaySwag[5762:122585] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'UITableView (<UITableView: 0x7fb361823600; frame = (0 0; 375 667); clipsToBounds = YES; opaque = NO; autoresize = W+H; 
gestureRecognizers = <NSArray: 0x608000049f60>; 
layer = <CALayer: 0x608000035100>; contentOffset: {0, -64}; contentSize: {375, 665}>) failed to obtain a cell from its dataSource (<ApplePaySwag.SwagListViewController: 0x7fb3614068e0>)' 
*** First throw call stack: 
(
0 CoreFoundation      0x00000001050dd34b __exceptionPreprocess + 171 
1 libobjc.A.dylib      0x0000000104a5f21e objc_exception_throw + 48 
2 CoreFoundation      0x00000001050e1442 +[NSException raise:format:arguments:] + 98 
//code removed for brevity 
libc++abi.dylib: terminating with uncaught exception of type NSException 

SwagListViewController.swift

import UIKit 

class SwagListViewController: UITableViewController { 

    var swagList = [ 
     Swag( image: UIImage(named: "iGT"), 
       title: "iOS Games by Tutorials", 
       price: 54.00, 
       type: SwagType.Electronic, 
       description: "This book is for beginner to advanced iOS developers. Whether you are a complete beginner to making iOS games, or an advanced iOS developer looking to learn about Sprite Kit, you will learn a lot from this book!"), 

    // code removed for brevity 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath) as! SwagCell 

     let object = swagList[indexPath.row] 
     cell.titleLabel.text = object.title 
     cell.priceLabel.text = "$" + object.priceString 
     cell.swagImage.image = object.image 
     return cell 
    } 

    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if segue.identifier == "showDetail" { 
      let object = swagList[self.tableView.indexPathForSelectedRow!.row] 
     (segue.destination as! BuySwagViewController).swag = object 
     } 
    } 

} 

SwagCell.swift

import UIKit 

class SwagCell: UITableViewCell { 
    @IBOutlet weak var titleLabel: UILabel! 
    @IBOutlet weak var priceLabel: UILabel! 
    @IBOutlet weak var swagImage: UIImageView! 
} 
+0

什麼是你的代碼在'的tableView:的cellForRowAtIndexPath:'你 – Larme

+0

剛剛更新了一些代碼,以便您可以更好地瞭解您的問題 – user2325154

+0

您是否找到了解決方案? –

回答

-1

幽祕ght在這裏找到你的答案stackoverflow.com/questions/40157812/

「出現錯誤是因爲cellForRowAtIndexPath的簽名是錯誤的。在斯威夫特3這是

(override) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 

,使用簡便方法

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for:indexPath) 

它總是返回一個有效的非可選電池「

相關問題