2016-12-27 80 views
1

我正在開發一個應用程序,使用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) 
     } 

在我的迴應總圖像爲四...但它獲取最後一個意象...... 幫我獲取所有圖像

回答

0

它只顯示最後一個因爲你在循環內調用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) 

這裏指的細節類https://github.com/zvonicek/ImageSlideshow/blob/master/ImageSlideshow/Classes/Core/ImageSlideshow.swift

+0

正在逐漸images.append(alamofiresource)錯誤ie.argument [AlamofireSource]不符合預期的類型輸入商店 – user7333282

+0

嘗試改變'VAR圖像= [ AlamofireSource]()' – xmhafiz

+0

給出同樣的錯誤,因爲images.append(alamofiresource)ie.argument [AlamofireSource]不符合預期的類型AlamofireSource – user7333282