我在CollectionView中使用了CollectionView模块。旋转木马视图在我的UICollectionViewCell中。
我的代码如下。
class CelebrityDetailHeaderCell: UICollectionViewCell, UITextFieldDelegate, SDCycleScrollViewDelegate, iCarouselDataSource, iCarouselDelegate {
@IBOutlet weak var backgroudLab: UILabel!
@IBOutlet weak var name_en: UILabel!
@IBOutlet weak var name_tw: UILabel!
@IBOutlet weak var intro: UILabel!
@IBOutlet weak var DetailImg: UIImageView!
@IBOutlet weak var iCarouselView: iCarousel!
let screenWidth = UIScreen.mainScreen().bounds.width
let screenHeight = UIScreen.mainScreen().bounds.height
override func awakeFromNib() {
super.awakeFromNib()
iCarouselView.delegate = self
iCarouselView.dataSource = self
iCarouselView.type = .Linear
}
func numberOfItemsInCarousel(carousel: iCarousel) -> Int {
return 1
}
func carousel(carousel: iCarousel, viewForItemAtIndex index: Int, reusingView view: UIView?) -> UIView {
let tempView = UIView(frame: CGRect(x: 0, y: screenWidth/2, width: screenWidth, height: screenWidth/2))
tempView.backgroundColor = UIColor.redColor()
return tempView
}
func carousel(carousel: iCarousel, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
if option == iCarouselOption.Spacing {
return 1.2
}
return value
}}
错误消息如下所示
由于“NSInvalidArgumentException”异常终止应用程序,原因:'-NSObject numberOfItemsInCarousel::未识别的选择器发送到实例0x7f99bb3734a0‘
我已经设置了numberOfItemsInCarousel,为什么错误消息会显示这一点。有人帮我吗?谢谢。
发布于 2016-10-21 08:54:41
看,您需要在单元格中添加一个dealloc方法。当您的单元正在被解除分配,而iCarousel委托将该方法调用到某个已分配的实例时,这就是它崩溃的原因。
编写这样的dealloc方法
- (void)dealloc{
iCarouselView.delegate = nil
iCarouselView.dataSource = nil
}https://stackoverflow.com/questions/40103276
复制相似问题