因此,我创建了一个iCarousel并能够成功地运行它。不过,我确实需要在视图控制器上加载多个旋转木马。我找到了多个iCarousels代码,并试图使其适应Swift。不幸的是,现在我得到了一个Thread1信号SIGABRT,它显示在行“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
}
}}
发布于 2017-05-29 22:56:17
我可以重新创建您的错误,它是由shirtsArray为空引起的,所以行
shirtsView.image = UIImage(named: "\(shirtsArray.object(at: index))")导致您遇到的异常。
我不知道为什么,但是如果你移动线
shirtsArray = ["StarWarsBlackFittedT.jpg", "CollaredFittedWhiteWithBeigeSplash.jpg", "CollaredWhiteWithZigzagLightBlueStripes.jpg", "ClooaredBlackWithWhiteStripes.jpg", "CollaredFittedNavyBlue.jpg"]如果只是在分配给hatsArray的任务之下,那么它就能工作。
您的viewForItemAt函数有点混乱。在决定需要哪一个之前,为什么要为这两个旋转木马创建图像/视图?
https://stackoverflow.com/questions/44250784
复制相似问题