如果单元格是第一个,则代码在以下行中崩溃
let nativeAdd = nativeAdsManager.nextNativeAd() as FBNativeAd?
我猜广告还没有准备好或什么的。但是不应该崩溃!!!我尝试将其放入 do-try-catch 中,但没有帮助。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
if (self.shouldShowAd(indexPath))
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(NSStringFromClass(AdCell), forIndexPath: indexPath) as! AdCell
let nativeAdd = nativeAdsManager.nextNativeAd() as FBNativeAd?
if (nativeAdd != nil)
{
cell.setDetails(nativeAdd!)
return cell
}
else
{
return self.createRegularCell(collectionView, cellForItemAtIndexPath: indexPath)
}
}
else
{
return self.createRegularCell(collectionView, cellForItemAtIndexPath: indexPath)
}
}