如何使用swift将图像字符串值传递给imageslide
问题描述:
我正在开发一个应用程序,使用swift 2.2在我的应用程序中使用图像幻灯片显示通过引用此链接https://github.com/zvonicek/ImageSlideshow我想传递图像字符串连接url ....如何使用swift将图像字符串值传递给imageslide
图像串是从JSON数据得到:
{
"Values Of Image":[{
"image":"apple.png,jewels.png,gun.png,mango.png"
}]
}
这仅仅是一个例子JSON数据,但我喜欢这个
获取数据现在我可以现在能够独立字符串我想传递的价值alamofire来源(imageslide)
编码控制器:
鉴于没有负载:
let MyImageSlide = json["Values Of Image"][0]["image"].stringValue
let parts = MyImageSlide.componentsSeparatedByString(",")
for numbers in parts{
print("image String:\(numbers)")
let alamofireSource = [AlamofireSource(urlString: "https://www.something.com" + numbers as String)!]
self.SecondImageShow.backgroundColor = UIColor.whiteColor()
self.SecondImageShow.pageControlPosition = PageControlPosition.UnderScrollView
self.SecondImageShow.pageControl.currentPageIndicatorTintColor = UIColor.lightGrayColor()
self.SecondImageShow.pageControl.pageIndicatorTintColor = UIColor.blackColor()
self.SecondImageShow.contentScaleMode = UIViewContentMode.ScaleAspectFill
self.SecondImageShow.setImageInputs(alamofireSource)
}
在我的回应总图像为四...但它获取最后一个意象...... 帮我获取所有图像
答
它只显示最后一个因为你在循环内调用setImageInputs
。
setImageInputs
应该调用图像源的数组。您的更改应该如下所示。
// create array of image sources
var images = [InputSource]()
for numbers in parts{
let alamofireSource = AlamofireSource(urlString: "https://www.something.com" + numbers as String)!
images.append(alamofireSource)
}
self.SecondImageShow.backgroundColor = UIColor.whiteColor()
self.SecondImageShow.pageControlPosition = PageControlPosition.UnderScrollView
self.SecondImageShow.pageControl.currentPageIndicatorTintColor = UIColor.lightGrayColor()
self.SecondImageShow.pageControl.pageIndicatorTintColor = UIColor.blackColor()
self.SecondImageShow.contentScaleMode = UIViewContentMode.ScaleAspectFill
// load the array here
self.SecondImageShow.setImageInputs(images)
正在逐渐images.append(alamofiresource)错误ie.argument [AlamofireSource]不符合预期的类型输入商店 – user7333282
尝试改变'VAR图像= [ AlamofireSource]()' – xmhafiz
给出同样的错误,因为images.append(alamofiresource)ie.argument [AlamofireSource]不符合预期的类型AlamofireSource – user7333282