加载指示器直到tableView加载

时间:2015-10-17 13:41:41

标签: ios swift uitableview asynchronous

我正在使用Parse为标题加载一些数据,为ImageView和ratingView加载http req。我还有一个包含2个选项的段控制视图。 我把一个指示器放在显示图像的位置,但是当我向下滚动时 或者当我按下另一段(不同的电影)时,我得到1-2秒的上一张图像,ratingView,标题,然后它们立即改变。显然不是全部在一起。我可以以某种方式同步更改或指示等待加载'直到一切都加载?

func segmentView(segmentView: SMSegmentView, didSelectSegmentAtIndex index: Int) {
        self.currentSegmentSelected = index
        loadData().findObjectsInBackgroundWithBlock { [weak self] objects, error in
            if error == nil {
                dispatch_async(dispatch_get_main_queue(), {
                    self?.loadObjects()
                })}
            }
    }

queryForTable(解析)

override func queryForTable() -> PFQuery {
let query:PFQuery = PFQuery(className:"Movies")
        if(objects?.count == 0)
        {
            query.cachePolicy = PFCachePolicy.CacheThenNetwork
        }
        if self.currentSegmentSelected == 0 {
            query.whereKey("genres", containsString: "Adventure")
        }
        else if currentSegmentSelected == 1 {
            query.whereKey("genres", containsString: "Comedy")
        }
        return query
    }

的cellForRowAtIndexPath

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
        let cellIdentifier:String = "cell"
        var cell:TableCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? TableCell
        if(cell == nil) {
            cell = TableCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier)
        }

 //???      indicator.startAnimating()
 //???       indicator.backgroundColor = UIColor.whiteColor()

    if let pfObject = object {

        PFCloud.callFunctionInBackground("averageStars", withParameters: ["movieId":pfObject["movieId"]]) {
            (response: AnyObject?, error: NSError?) -> Void in
            if let rating = response as! Float? {
            cell?.rating.rating = rating
            }}

        if let movieId = pfObject["movieId"] as? Int {
            if RecommendedSet.ratings[movieId] == nil {
                cell?.userRating.rating = 0
            } else {
               cell?.userRating.rating = RecommendedSet.ratings[movieId]!
            }
        }

        cell?.title?.text = pfObject["title"] as? String

        if let Id = pfObject["tmdbId"] as? Int {
        Alamofire.request(.GET, timdb , parameters: ["api_key": APIkey])
            .responseJSON { response in
                if let JSON...
                let imgData: NSData = NSData(contentsOfURL: imgURL)!                   
                dispatch_async(dispatch_get_main_queue(), {
                    cell?.posterView?.image = UIImage(data: imgData)
             //???  self.indicator.stopAnimating()
             //??? self.indicator.hidesWhenStopped = true
                                    })
                }}}}}}}
    return cell
}

0 个答案:

没有答案