简体   繁体   English

Dribble Api返回错误数据

[英]Dribble Api returning wrong data

Hi guys so recently there has been a bug of getting data from Dribble.. 嗨,大家好,最近出现了从Dribble获取数据的错误。

My Dribbble client IOS shows shots on the main screen and if you click on a collectionView Cell it takes you to the detail of the shot.. 我的Dribbble客户端IOS在主屏幕上显示镜头,如果您单击collectionView单元格,则会带您到镜头的细节。

And i am getting Dribble Data through its api with this method. 我正在使用此方法通过其api获取Dribble Data。

The Code for the getShots Method getShots方法的代码

 class func getShots(url: String, callback:(([Shot]) -> Void)){
        var shots = [Shot]()
        let url = url + "&access_token=" + Config.ACCESS_TOKEN

        HttpService.getJSON(url){ (jsonData) -> Void in

            for shotData in jsonData {
                let shot = Shot(data: shotData as! NSDictionary)
                shots.append(shot)
            }

            let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
            dispatch_async(dispatch_get_global_queue(priority, 0), { () -> Void in
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    callback(shots)
                })
            })
        }
    }

The Code for the getJSON method.. getJSON方法的代码。

class HttpService {
    class func getJSON(url: String, callback:((NSArray) -> Void)) {
        let nsURL = NSURL(string: url)!
        Alamofire.request(.GET, nsURL).response { (request, response, data, error) -> Void in
            if error != nil{
                print("error")
            }

            if data != nil {
                let jsonData = (try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)) as! NSArray
                   callback(jsonData)
            }
        }
    }
}

This code is above which loads The Shot JSON Data successfully.. So when i debug it on the self.shots = shots line it returns something like this.. 上面的代码成功加载了Shot JSON数据。因此,当我在self.shots = shots行上对其进行调试时,它将返回类似的内容。

The log when debugging on the self.shots = shots line 在self.shots = shots行上调试时的日志

It all works fine.. and the code for the class of Detail of a Shot... I have been using dynamic tableView to show the Shot Detail 一切正常..和镜头细节类的代码...我一直在使用动态tableView来显示镜头细节

The code in ShotDetail the code where the label are allocated their text.. basically The TableView Data Source Method.. ShotDetail中的代码是为标签分配文本的代码。基本上是TableView数据源方法。

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 2
    }




    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        if section == 0 {
         return 9
        } else {
         return comments.count
        }
    }



    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        if indexPath.section == 0 {
         if indexPath.row == 0 {
         let cell = tableView.dequeueReusableCellWithIdentifier("Cell1", forIndexPath: indexPath) as! vlcTableViewCell

            // Configure the cell
     // the views . likes. and the comment Count label are allocated
            cell.viewsCount.text = "\(shot.viewsCount)"
            cell.likesCount.text = "\(shot.likesCount)"
            cell.commentCount.text = "\(shot.commentCount)"

         return cell
        } else if indexPath.row == 1 {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as! descCell

           // Configure the Cell
   // the text for the labels
            cell.usernameLabel.text = "\(shot.user.username)"
            cell.descriptionLabel.text = "\(shot.description)"
            cell.profileImageView.sd_setImageWithURL(NSURL(string: shot.user.avatarUrl), placeholderImage: UIImage(named: "2"))

        return cell

        } else if indexPath.row == 2 {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell4", forIndexPath: indexPath) as! teamCell
            if shot.team == nil{
              cell.teamNameLabel.text = "Team"
            } else {
            cell.teamNameLabel.text = "\(shot.team.name)"
            }
        return cell
        } else  if indexPath.row == 4 {
            let cell = tableView.dequeueReusableCellWithIdentifier("Cell5", forIndexPath: indexPath) as! reboundShotsCount
            cell.reboundCountLabel.text = "\(shot.reboundCount)"

            return cell

        } else {
         let cell = tableView.dequeueReusableCellWithIdentifier("Cell10", forIndexPath: indexPath) as! CommentCell

            let comment = comments[indexPath.row]
            cell.nameLabel.text = comment.user.name
            cell.commentLabel.text = comment.body

            cell.avatarImageView.alpha = 0.0



            cell.avatarImageView.sd_setImageWithURL(NSURL(string: comment.user.avatarUrl), placeholderImage: UIImage(named: "2"), completed: { (image, error, cacheType, url) -> Void in
                cell.avatarImageView.alpha = 1.0
                // Animate the imageView after the image is loaded
                cell.animationView.layer.cornerRadius = 25
                cell.animationView.delay = 0
                cell.animationView.duration = 0.5
                cell.animationView.type = "popAlpha"
                cell.animationView.startCanvasAnimation()
            })

        cell.dateLabel.text = comment.date

            return cell
        }
    }

and the Code for the Shot Class.. From where i get all the data to set to the labels 以及Shot类的代码。从这里我可以将所有数据设置为标签

import Foundation

class Shot: DribbbleBase {

    var imageUrl : String!
    var htmlUrl : String!
    var commentsUrl : String!
    var bucketsUrl : String!
    var likesUrl : String!
    var attachmentUrl : String!
    var reboundUrl : String!

    var title : String!
    var date : String!
    var description : String!
    var commentCount : Int!
    var viewsCount : Int!
    var likesCount : Int!
    var bucketsCount : Int!
    var attachmentsCount : Int!
    var reboundCount : Int!
    var imageUrll : String!
    var teamUrl : String!

    var user : User!
    var team : Team!

   override init(data: NSDictionary) {
        super.init(data: data)

        self.commentCount = data["comments_count"] as! Int
        self.likesCount = data["likes_count"] as! Int
        self.viewsCount = data["views_count"] as! Int
        self.bucketsCount = data["buckets_count"] as! Int
        self.attachmentsCount = data["attachments_count"] as! Int
        self.reboundCount = data["rebounds_count"] as! Int

        self.commentsUrl = Utils.getStringFromJSON(data, key: "comments_url")
        self.bucketsUrl = Utils.getStringFromJSON(data, key: "buckets_url")
        self.likesUrl = Utils.getStringFromJSON(data, key: "likes_url")
        self.title = Utils.getStringFromJSON(data, key: "title")
        self.attachmentUrl = Utils.getStringFromJSON(data, key: "attachments_url")
        self.reboundUrl = Utils.getStringFromJSON(data, key: "rebounds_url")
        self.teamUrl = Utils.getStringFromJSON(data, key: "teams_url")

        let dateInfo = Utils.getStringFromJSON(data, key: "created_at")
        self.date = Utils.formatDate(dateInfo)

        let desc = Utils.getStringFromJSON(data, key: "description")
        self.description = Utils.stripHTML(desc)

        let images = data["images"] as! NSDictionary
        self.imageUrl = Utils.getStringFromJSON(images, key: "normal")
        self.imageUrll = Utils.getStringFromJSON(images, key: "hidpi")


        let tags = data["tags"] as! NSArray

      if let userData = data["user"] as? NSDictionary {
        self.user = User(data: userData)
    }

    if let teamData = data["team"] as? NSDictionary {
      self.team = Team(data: teamData)
    }

  }
}

Now the problem occurs when i tap on the cell to go to the next cell. 现在,当我点击该单元格转到下一个单元格时,就会出现问题。 before that if i debug in the Shot class.. 在此之前,如果我在Shot类中进行调试。

The data looks like this 数据看起来像这样

The Log Which shows the data returned 显示返回数据的日志

and now whenever i click on the cell. 现在,每当我单击单元格时。 to go to the detail. 去细节。 the data returns only 7 value for the exact thing which in the first was returning all the values needed.. 数据仅返回7个确切值,而第一个值恰好是返回所有需要的值。

the code i am using to push the data in PopularShotsCollectionViewController is this. 我用来在PopularShotsCollectionViewController中推送数据的代码是这个。

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if(segue.identifier == "1"){
          let selectedItems = collectionView!.indexPathsForSelectedItems()

            if let sItem = selectedItems as [NSIndexPath]!{
                let shot = shots[sItem[0].row]
                let controller = segue.destinationViewController as! ShotDetail
                controller.shot = shot
            }

        }
    }

But the log only returns 7 value in that.. 但是日志中只返回7值。

https://www.dropbox.com/s/4vkgg7a3f44fg35/Screen%20Shot%202016-03-28%20at%2014.40.23.png?dl=0

I have put the link in a code block as i cant post more than 2 links. 我将链接放在代码块中,因为我不能发布两个以上的链接。

Any help will be really appreciated.. 任何帮助将不胜感激..

Thanks Aryan 谢谢雅利安

let shot = shots[sItem[0].row] Might be the issue. let shot = shots [sItem [0] .row]可能是问题所在。 You're passing the same index to the DetailVC . 您正在将相同的索引传递给DetailVC You could save an array of the selected shots then pass it to shot variable in your DetailVC (If the shot variable is an array of shots ) 您可以保存所选镜头的数组,然后将其传递到DetailVC的镜头变量(如果镜头变量是shots数组)

var selectedIndex = NSIndexPath()
    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

        selectedIndex = indexPath
    }
 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if(segue.identifier == "1"){
          let selectedItems = collectionView!.indexPathsForSelectedItems()
              let selectedShots = shots[selectedIndex.row]
                let controller = segue.destinationViewController as! ShotDetail
                controller.shot = selectedShots
            }

        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM