Swift 3迁移后UICollectionView被破坏了吗?

时间:2016-09-21 16:07:23

标签: ios swift swift3 xcode8

在我的项目中使用Swift 3转换器后,我在加载UICollectionViewController的子类时不断崩溃。下面是我的代码,其中包含集合视图的相关方法。

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {  
  return photos.count  
}  

override func collectionView(_ collectionView: UICollectionView, c`enter code here`ellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: tileReuseIdentifier, for: indexPath) as! TileCollectionViewCell  
cell.captionLabel.text = photos[(indexPath as NSIndexPath).item].caption
cell.captionLabel.adjustsFontSizeToFitWidth = true
cell.imageView.image = photos[(indexPath as NSIndexPath).item].image
cell.layer.cornerRadius = 10
cell.layer.shadowPath = UIBezierPath(roundedRect: cell.frame, cornerRadius: cell.layer.cornerRadius).cgPath  
return cell
}  

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
return CGSize(width: cellSize, height: cellSize)
}  

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex indexPath: IndexPath) -> CGFloat {
return spacing
}  

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let reusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerReuseIdentifier, for: indexPath) as! HeaderCollectionReusableView  

reusableView.setupView()  

return reusableView  
}  

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: collectionView.frame.width, height: cellSize-20)
}  

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(topMargin, spacing, bottomMargin, spacing)
}

这是崩溃时的堆栈跟踪:

libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath:
    0x100a549e0 <+0>:  stp    x20, x19, [sp, #-32]!
    0x100a549e4 <+4>:  stp    x29, x30, [sp, #16]
    0x100a549e8 <+8>:  add    x29, sp, #16              ; =16 
    0x100a549ec <+12>: mov    x19, x0
    0x100a549f0 <+16>: cbz    x19, 0x100a54a18          ; <+56>
    0x100a549f4 <+20>: mov    x0, x19
    0x100a549f8 <+24>: bl     0x100a7cfd4               ; function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of Foundation.IndexPath.init (nsIndexPath : __ObjC.NSIndexPath) -> Foundation.IndexPath
    0x100a549fc <+28>: mov    x20, x0
    0x100a54a00 <+32>: mov    x0, x19
    0x100a54a04 <+36>: bl     0x100abcfe4               ; symbol stub for: objc_release
    0x100a54a08 <+40>: mov    x0, x20
    0x100a54a0c <+44>: ldp    x29, x30, [sp, #16]
    0x100a54a10 <+48>: ldp    x20, x19, [sp], #32
    0x100a54a14 <+52>: ret    
->  0x100a54a18 <+56>: brk    #0x1

有些搜索引导我https://bugs.swift.org/browse/SR-2103https://bugs.swift.org/browse/SR-2417

奇怪的是,当我在上述方法的开头设置断点时,应用程序会在到达任何断点之前崩溃。 viewDidLoad执行并返回。然后应用程序因上述错误而崩溃。

有人可以帮忙吗?

0 个答案:

没有答案