iCarousel - Thread1 信号 SIGABRT
iCarousel - Thread1 signal SIGABRT
所以我创建了一个 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
}
}
}
我可以重现您的错误,这是由 shirtsArray 为空引起的,因此行
shirtsView.image = UIImage(named: "\(shirtsArray.object(at: index))")
导致您遇到的异常。
我不知道为什么,但是如果你移动这条线
shirtsArray = ["StarWarsBlackFittedT.jpg", "CollaredFittedWhiteWithBeigeSplash.jpg", "CollaredWhiteWithZigzagLightBlueStripes.jpg", "ClooaredBlackWithWhiteStripes.jpg", "CollaredFittedNavyBlue.jpg"]
只要赋值给hatsArray,就可以了。
您的 viewForItemAt 函数有点乱。为什么要在决定需要哪一个之前为两个轮播创建 images/views?
所以我创建了一个 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
}
}
}
我可以重现您的错误,这是由 shirtsArray 为空引起的,因此行
shirtsView.image = UIImage(named: "\(shirtsArray.object(at: index))")
导致您遇到的异常。
我不知道为什么,但是如果你移动这条线
shirtsArray = ["StarWarsBlackFittedT.jpg", "CollaredFittedWhiteWithBeigeSplash.jpg", "CollaredWhiteWithZigzagLightBlueStripes.jpg", "ClooaredBlackWithWhiteStripes.jpg", "CollaredFittedNavyBlue.jpg"]
只要赋值给hatsArray,就可以了。
您的 viewForItemAt 函数有点乱。为什么要在决定需要哪一个之前为两个轮播创建 images/views?