[英]UICollectionView and Supplementary View crash
我有一個UICollectioView工作正常。 有兩種方法可以訪問此頁面。
除了一個案例,一切都很好。
如果用戶在聊天中,然后他退出應用程序(主頁按鈕),那么他會得到推送通知,他按下它並且應用程序崩潰。
崩潰:
2015-09-25 10:28:15.140 Quest [298:16922] *斷言失敗 - [UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:],/ BuildRoot / Library / Cache / com.apple.xbs / Sources / UIKit / UIKit-3505.16 / UICollectionView.m:1519 2015-09-25 10:28:15.146 Quest [298:16922] *由於未捕獲的異常'NSInternalInconsistencyException'而終止應用程序,原因:'未設置UICollectionView數據源'***首先拋出調用堆棧:(0x1828b4f5c 0x1973b7f80 0x1828b4e2c 0x1837a3f3c 0x187f97a38 0x187e6ebd4 0x187e6fb54 0x187e69b88 0x187e0700c 0x18760df14 0x187608b20 0x1876089e0 0x18760807c 0x187607dd0 0x1880c0bd4 0x18286c48c 0x18286bdc4 0x182869d4c 0x182798dc0 0x18d8ec088 0x187e72f60 0x100215590 0x197be28b8)的libc ++ abi.dylib:與類型NSException的未捕獲的異常終止
推送處理程序中的代碼
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let home = storyboard.instantiateViewControllerWithIdentifier("home") as! HomeViewController
let chat = storyboard.instantiateViewControllerWithIdentifier("chat") as! ChatViewController
var controllers : [UIViewController] = [login, chat]
NotificationManager.handleNotification(userInfo, controllers: &controllers, storyboard: storyboard)
navC.viewControllers = controllers
self.window?.makeKeyAndVisible()
}
集合設置代碼
@IBOutlet weak var chatCollectionView: UICollectionView! {
didSet {
chatCollectionView.registerNib(UINib(nibName: "ChatTimeStampCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ChatTimeStampCell")
chatCollectionView.registerNib(UINib(nibName: "ChatReceiverCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ChatReceiverCell")
chatCollectionView.registerNib(UINib(nibName: "ChatSenderCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ChatSenderCell")
chatCollectionView.registerNib(UINib(nibName: "ChatHeaderCollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "ChatHeaderCell")
chatCollectionView.dataSource = self
chatCollectionView.delegate = self
}
}
如果您在集合視圖中使用自定義布局,請檢查其數據源是否為零:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
結果應如下所示:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
if (self.collectionView.dataSource != nil) {
// Your layout code
return array;
}
return nil;
}
此更改解決了以下問題:
- 斷言失敗 - [UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:]
您還可以檢查以下主題,但在我的情況下它們沒有解決任何問題: UICollectionView和Supplementary View(標題)
如果節標題隱藏在UICollectionView中,則刪除空白空間
希望它會對你有所幫助,你不會浪費我那么多的時間。 @eeeee謝謝你指點我正確的方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.