簡體   English   中英

iOS / Swift:tableView cellForRowAtIndexPath崩潰

[英]iOS/Swift: tableView cellForRowAtIndexPath crash

我遇到了第389行的EXC_BREAKPOINT崩潰

386    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
387        let cell = tableView.dequeueReusableCellWithIdentifier("StationsCell", forIndexPath: indexPath)
388        cell.textLabel?.text = self.suggestionStations?[indexPath.row]
389        return cell
390    }

這是來自Crashlytics的崩潰報告,發生在2%的用戶:

Thread : Crashed: com.apple.main-thread 0 Trenìt! 0x10004a2e4 specialized MasterViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (MasterViewController.swift:389) 1 Trenìt! 0x100046488 @objc MasterViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (MasterViewController.swift) 2 UIKit 0x18c6b239c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 544 3 UIKit 0x18c6a6fc4 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360 4 UIKit 0x18c49cc60 -[UITableView layoutSubviews] + 172 5 UIKit 0x18c3b9874 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572 6 QuartzCore 0x18bd11d58 -[CALayer layoutSublayers] + 168 7 QuartzCore 0x18bd0c944 CA::Layer::layout_if_needed(CA::Transaction*) + 320

知道為什么會這樣嗎?

崩潰是由於suggestionStations數組在索引處沒有值而引起的。

當數組重置為0時,我沒有在表上調用ReloadData() 。因此,當索引處的值不再存在時,表函數仍然在競爭條件中被調用。

修復是在重置數組后調用ReloadData()。 否則可能會檢查是否為數組定義了索引,但如果每次都正確調用reloadData,則不需要這樣做。

我們遇到了同樣的問題。 此問題在iOS 10 beta1上100%可重現。

雖然很難相信,但我們設法通過在故事板上提供一個非常短的單元格標識符來解決問題。 就像“PhoneContactCell”重命名為“PCell”一樣。

經過一些調查,我們認為這是一個故事板錯誤:如果復制和修改單元格原型,那么它可能會有這個問題。

確保您已將主要標識符設置為Main.Storyboard “StationsCell”。 選擇Cell並轉到Attributes Inspector。

還要在函數之前添加override ,因此它應該override func

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM