ios – 完成处理程序在viewDidLoad中不工作?

前端之家收集整理的这篇文章主要介绍了ios – 完成处理程序在viewDidLoad中不工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用这个 library在我的应用程序的横幅.我正在尝试通过解析JSON来获取链接.

图像在幻灯片视图中未显示.如果我按幻灯片视图,之后一切正常.我以为我的完成处理程序有一些问题.
但我不能解决它:)

@IBOutlet weak var slideshow: ImageSlideshow!
var transitionDelegate: ZoomAnimatedTransitioningDelegate?
var Banner : [AlamofireSource] = []

override func viewDidLoad() {
        super.viewDidLoad()
        Banners { (imagesource) in
            if imagesource != nil {
                self.bannershow()
            }
        }
  }

    func Banners(completionHandler: ([AlamofireSource]?) -> ()) -> (){
        Alamofire.request(.GET,"http://46.420.116.11/mobileapp/gps/api.PHP?rquest=get_banners")
            .responseJSON{ response in
                if let data = response.result.value{
                    let json = JSON(data)
                    let count = json["image_path"].count
                    for index in 0...count-1 {
                        let image :String = json["image_path"][index].stringValue
                        let source : AlamofireSource = AlamofireSource(urlString: image)!
                        self.Banner.append(source)
                    }
                    completionHandler(self.Banner)
                }
        }
  }

    func bannershow(){
        self.slideshow.backgroundColor = UIColor.whiteColor()
        self.slideshow.slideshowInterval = 2.0
        self.slideshow.contentScaleMode = UIViewContentMode.ScaleToFill
        self.slideshow.setImageInputs(self.Banner)

        let recognizer = UITapGestureRecognizer(target: self,action: "click")
        self.slideshow.addGestureRecognizer(recognizer)
        }

 func click() {
        let ctr = FullScreenSlideshowViewController()
        ctr.pageSelected = {(page: Int) in
            self.slideshow.setScrollViewPage(page,animated: false)
        }

        ctr.initialPage = slideshow.scrollViewPage
        ctr.inputs = slideshow.images
        self.transitionDelegate = ZoomAnimatedTransitioningDelegate(slideshowView: slideshow);
        ctr.transitioningDelegate = self.transitionDelegate!
        self.presentViewController(ctr,animated: true,completion: nil)
    }

解决方法

你可能有一个线程问题.横幅完成处理程序不能保证主线程被调用.您需要在做任何触及属性或(特别是)界面的事情之前明确地走出主线程.

猜你在找的iOS相关文章