iCarousel - Thread1信号SIGABRT

时间:2017-05-29 22:02:07

标签: swift3 icarousel

所以我创建了一个iCarousel并且能够成功运行它。但我确实需要在viewcontroller上加载多个轮播。我找到了多个iCarousels代码并尝试将其改编为Swift。现在不幸的是,我得到一个Thread1信号SIGABRT,显示在“class AppDelegate”行。真的不知道为什么会这样做。

请帮帮我!这是我对ViewController的代码

class ChangeRoomViewController: UIViewController, iCarouselDataSource, 
iCarouselDelegate {

    var hatsArray : NSMutableArray = NSMutableArray()
    var shirtsArray : NSMutableArray = NSMutableArray()

@IBOutlet weak var carousel1: iCarousel!
@IBOutlet weak var carousel2: iCarousel!

override func viewDidLoad() {

    super.viewDidLoad()

    hatsArray = ["TopHat.jpeg", "WhiteBrimHat.jpeg", "StoutHat.jpg", "BaseballCapBlackw:Red.jpg", "WhiteBaseballCap.jpg"]
    carousel1.type = iCarouselType.cylinder
    carousel1.reloadData()

    shirtsArray = ["StarWarsBlackFittedT.jpg", "CollaredFittedWhiteWithBeigeSplash.jpg", "CollaredWhiteWithZigzagLightBlueStripes.jpg", "ClooaredBlackWithWhiteStripes.jpg", "CollaredFittedNavyBlue.jpg"]
    carousel2.type = iCarouselType.cylinder
    carousel2.reloadData()
}

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {

    var hatsView : UIImageView!
    var shirtsView : UIImageView!

    if view == nil {
        hatsView = UIImageView(frame: CGRect(x: 16, y: 65, width: 90, height: 60))
        hatsView.contentMode = .scaleAspectFit
        shirtsView = UIImageView(frame: CGRect(x: 16, y: 133, width: 90, height: 60))
        shirtsView.contentMode = .scaleAspectFit
    } else {
        hatsView = view as! UIImageView
        shirtsView = view as! UIImageView
    }

    hatsView.image = UIImage(named: "\(hatsArray.object(at: index))")
    shirtsView.image = UIImage(named: "\(shirtsArray.object(at: index))")

    if (carousel == carousel1) {
        return hatsView
    }else {
        return shirtsView
    }

}

func numberOfItems(in carousel: iCarousel) -> Int {
    if (carousel == carousel1) {
        return hatsArray.count
    }else {
        return shirtsArray.count
    }
}

}

1 个答案:

答案 0 :(得分:2)

我可以重新创建你的错误,这是由于ShirtArray是空的,所以行

9
5
10
21
10

导致您遇到的异常。

我不知道为什么,但如果你移动线

shirtsView.image = UIImage(named: "\(shirtsArray.object(at: index))")

只是在hatsArray的任务下,然后就可以了。

你的viewForItemAt函数有点乱。为什么在决定哪一个需要之前为两个轮播创建图像/视图?