Crashlytics给了我下面的堆栈跟踪。崩溃发生的不一致。发生在所有的iOS 9设备上,但非常罕见。无法找出问题的来源。没有发生在任何设备上,我已经尝试崩溃了过去3天。
Crashed: com.apple.main-thread
0 cherish 0x10014ee18 specialized PersonalizeViewController.collectionView(UICollectionView, cellForItemAtIndexPath : NSIndexPath) -> UICollectionViewCell (PersonalizeViewController.swift:159)
1 cherish 0x1001497f0 @objc PersonalizeViewController.collectionView(UICollectionView, cellForItemAtIndexPath : NSIndexPath) -> UICollectionViewCell (PersonalizeViewController.swift)
2 UIKit 0x188aef3a8 <redacted> + 432
3 UIKit 0x188311adc <redacted> + 4628
4 UIKit 0x18830c808 <redacted> + 228
5 UIKit 0x1882a81e4 <redacted> + 656
6 QuartzCore 0x185c3a994 <redacted> + 148
7 QuartzCore 0x185c355d0 <redacted> + 292
8 QuartzCore 0x185c35490 <redacted> + 32
9 QuartzCore 0x185c34ac0 <redacted> + 252
10 QuartzCore 0x185c34820 <redacted> + 500
11 QuartzCore 0x185c2dde4 <redacted> + 80
12 CoreFoundation 0x183104728 <redacted> + 32
13 CoreFoundation 0x1831024cc <redacted> + 372
14 CoreFoundation 0x1831028fc <redacted> + 928
15 CoreFoundation 0x18302cc50 CFRunLoopRunSpecific + 384
16 GraphicsServices 0x184914088 GSEventRunModal + 180
17 UIKit 0x188316088 UIApplicationMain + 204
18 cherish 0x100142a50 main (AppDelegate.swift:19)
19 libdispatch.dylib 0x182bca8b8 (Missing)
它崩溃的代码是:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if collectionView.tag == 1 {
(---crash line---) let cell = select_date_collection_view.dequeueReusableCellWithReuseIdentifier(PERSONALIZE_SELECT_DATE_COLLECTION_CELL_IDENTIFIER, forIndexPath: indexPath) as! SelectDateCollectionViewCell
// Some changes to cell objects
return cell
} else if collectionView.tag == 2 {
let cell = select_time_collection_view.dequeueReusableCellWithReuseIdentifier(PERSONALIZE_SELECT_TIME_COLLECTION_CELL_IDENTIFIER, forIndexPath: indexPath) as! SelectTimeCollectionViewCell
// Some changes to cell objects
return cell
} else if collectionView.tag == 3 {
let cell = add_customization_collection_view.dequeueReusableCellWithReuseIdentifier(PERSONALIZE_ADD_CUSTOMIZATION_COLLECTION_CELL_IDENTIFIER, forIndexPath: indexPath) as! AddCustomizationCollectionViewCell
// Some changes to cell objects
return cell
}
let cell: UICollectionViewCell = UICollectionViewCell()
return cell
}
已初始化viewDidLoad()中的所有集合视图
select_date_collection_view.registerNib(UINib(nibName: "SelectDateCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: PERSONALIZE_SELECT_DATE_COLLECTION_CELL_IDENTIFIER)
select_date_collection_view.tag = 1
select_date_collection_view.dataSource = self
select_date_collection_view.delegate = self
select_date_collection_view.showsHorizontalScrollIndicator = false
select_date_collection_view.showsVerticalScrollIndicator = false
select_date_collection_view.reloadData()
select_time_collection_view.registerNib(UINib(nibName: "SelectTimeCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: PERSONALIZE_SELECT_TIME_COLLECTION_CELL_IDENTIFIER)
select_time_collection_view.tag = 2
select_time_collection_view.dataSource = self
select_time_collection_view.delegate = self
select_time_collection_view.showsHorizontalScrollIndicator = false
select_time_collection_view.showsVerticalScrollIndicator = false
hideSelectTimeView()
add_customization_collection_view.registerNib(UINib(nibName: "AddCustomizationCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: PERSONALIZE_ADD_CUSTOMIZATION_COLLECTION_CELL_IDENTIFIER)
add_customization_collection_view.tag = 3
add_customization_collection_view.dataSource = self
add_customization_collection_view.delegate = self
add_customization_collection_view.showsHorizontalScrollIndicator = false
add_customization_collection_view.showsVerticalScrollIndicator = false
hideCustomizationsView()
错误发生的不一致,这是一个主要的关注原因。因为我无法找出什么是错误的,从itunes或崩溃日志没有帮助。
2条答案
按热度按时间pbwdgjma1#
我终于拿到了一部死机的iPhone。结果发现有几个问题:
iOS、Crashlytics和iTunes的崩溃报告是完全无用的。代码崩溃的实际位置从来没有被他们标记出来,而是在调试模式下崩溃时被xcode标记出来。所以不要相信crashlytics或itunes生成的报告。
实际的问题是我从服务器上得到的时间是“HH:mm:ss”格式,我把它转换成“hh:mm a”格式,因为我想在UI上显示AM和PM。现在iOS做的一件伟大的事情是,如果用户的手机时间设置是24小时格式,就不会返回AM/PM,应用程序会崩溃,因为我没有检查返回的字符串是否为空。为了解决上述问题,我必须将区域设置为:
问题终于解决了。主要的教训是不要依赖于crashlytics或Itunes的报告
jqjz2hbq2#
注册此单元格-
然后在UICollectionViewCell()位置返回下面的代码链接-
在集合视图中,如果您返回一个空白单元格,应用程序会崩溃,因为空白单元格没有标识符。