我刚刚发布了我的移动应用程序的新版本,一切似乎都很顺利,但我在其中一个表格视图中遇到了一个奇怪的崩溃。 此崩溃发生在不同的设备(iPhone 7,iPhone 5s等)和不同的iOS版本(iOS 10,iOS 11等)上。 我试图发现一些内存泄漏或僵尸没有运气。这是我从Crashlytics收到的崩溃报告(此漏洞影响了0.44%的用户)。
#0. Crashed: com.apple.main-thread
0 App 0x1024d8d40 specialized ResultsViewController.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (ResultsViewController.swift)
1 App 0x1024d06e4 @objc ResultsViewController.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (ResultsViewController.swift)
2 UIKit 0x18dbcd474 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 668
3 UIKit 0x18dbcd9d8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
4 UIKit 0x18dbad670 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2140
5 UIKit 0x18d968f10 -[UITableView layoutSubviews] + 140
6 UIKit 0x18d895000 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1256
7 QuartzCore 0x1884650b4 -[CALayer layoutSublayers] + 184
8 QuartzCore 0x188469194 CA::Layer::layout_if_needed(CA::Transaction*) + 332
9 QuartzCore 0x1883d7f24 CA::Context::commit_transaction(CA::Transaction*) + 336
10 QuartzCore 0x1883fe340 CA::Transaction::commit() + 540
11 QuartzCore 0x1883ff180 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
12 CoreFoundation 0x18442f8b8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
13 CoreFoundation 0x18442d270 __CFRunLoopDoObservers + 412
14 CoreFoundation 0x18442d82c __CFRunLoopRun + 1292
15 CoreFoundation 0x18434e2d8 CFRunLoopRunSpecific + 436
16 GraphicsServices 0x1861dff84 GSEventRunModal + 100
17 UIKit 0x18d8fb880 UIApplicationMain + 208
18 App 0x1024614e4 main (AppDelegate.swift:15)
19 libdyld.dylib 0x183e7256c start + 4
只有一个报告有另外一行:
1 App 0xbca7c specialized ResultsViewController.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (ResultsViewController.swift:587)
这是我的cellForRowAt
方法:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if isResultsEmpty && indexPath.section == itinerariesIndex {
let cell = tableView.dequeueReusableCell(withIdentifier: "ShimmerCell", for: indexPath) as! ShimmerCell
if bookmark != nil {
cell.setup(true) // start shimmering
}
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "\(cellIdentifier)\(cellTypeIdentifier)Cell", for: indexPath) as! RoundTripCell
cell.delegate = self
let itinerary: Itinerary = self.dataSource[indexPath.section].getSectionItineraries()[indexPath.row] // line 587
if let _ = bookmark, indexPath.section == bookmarksIndex {
cell.setup(true, founded: self.founded) // start animation
} else {
cell.setup(false, founded: false) // stop animation
}
DispatchQueue.main.async {
let depTrip = itinerary.getTrips()[0]
cell.depOtaLogo.sd_setImage(with: URL(string: (depTrip.carrierMediumLogo)), placeholderImage: nil)
cell.depTimeLabel.text = depTrip.getDepartureArrivalTime()
cell.depDelay.text = depTrip.getDelayString()
cell.depIataLabel.text = depTrip.departureArrivalIATAString
cell.depStopLabel.text = depTrip.stopsString
cell.depDurationLabel.text = depTrip.getDurationString()
if self.searchParameters.tripType == .ROUND_TRIP {
let arrTrip = itinerary.getTrips()[1]
cell.arrOtaLogo.sd_setImage(with: URL(string: (arrTrip.carrierMediumLogo)), placeholderImage: nil)
cell.arrTimeLabel.text = arrTrip.getDepartureArrivalTime()
cell.arrDelay.text = arrTrip.getDelayString()
cell.arrIataLabel.text = arrTrip.departureArrivalIATAString
cell.arrStopLabel.text = arrTrip.stopsString
cell.arrDurationLabel.text = arrTrip.getDurationString()
}
cell.priceButton.tag = indexPath.row
let buttonTitle = (indexPath.section == self.bookmarksIndex && !self.founded) ? "" : itinerary.getOffers()[0].price + self.offlineSymbol
cell.priceButton.setTitle(buttonTitle, for: .normal)
cell.priceButton.isUserInteractionEnabled = false
if self.searchParameters.isOfflineSelected() {
cell.priceButton.isEnabled = false
} else {
cell.priceButton.isEnabled = true
}
}
return cell
}
我试图重现这种崩溃而没有运气。