Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 运球Api返回错误数据_Ios_Swift_Api - Fatal编程技术网

Ios 运球Api返回错误数据

Ios 运球Api返回错误数据,ios,swift,api,Ios,Swift,Api,嗨,伙计们,最近有一个从运球中获取数据的错误 我的Dribble client IOS会在主屏幕上显示快照,如果您单击collectionView单元格,它会将您带到快照的详细信息 我用这个方法通过api获取运球数据 getShots方法的代码 class func getShots(url: String, callback:(([Shot]) -> Void)){ var shots = [Shot]() let url = url + "&a

嗨,伙计们,最近有一个从运球中获取数据的错误

我的Dribble client IOS会在主屏幕上显示快照,如果您单击collectionView单元格,它会将您带到快照的详细信息

我用这个方法通过api获取运球数据

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)
                })
            })
        }
    }
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)
            }
        }
    }
}
上面的代码成功加载快照JSON数据。。 因此,当我在self.shots=shots行上调试它时,它会返回如下内容

一切都很好。。还有镜头细节类的代码。。。 我一直在使用动态tableView显示快照细节

shot中的代码详细说明了为标签分配文本的代码。。基本上是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
        }
    }
还有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)
    }

  }
}
现在,当我点击单元格转到下一个单元格时,问题就出现了。 在此之前,如果我在Shot类中调试

数据如下所示

现在每当我点击单元格。去细节。数据只返回7个值,而第一个值返回的正是所需的所有值

我用来在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
            }

        }
    }
但是日志中只返回7个值

https://www.dropbox.com/s/4vkgg7a3f44fg35/Screen%20Shot%202016-03-28%20at%2014.40.23.png?dl=0
我已经把一个代码块的链接,因为我不能张贴超过2个链接

任何帮助都将不胜感激

谢谢
雅利安人可能是个问题。您正在将相同的索引传递给
DetailVC
。您可以保存所选快照的数组,然后将其传递给
DetailVC
中的快照变量(如果快照变量是
快照的数组


你的问题非常模糊,包含了很多不必要的代码。你能把它截断一点并指出具体的问题吗?我已经把它缩减了@kye如果你认为它应该再缩减一点请告诉我..它仍然可以缩减一点(需要执行很多代码)。究竟是什么问题?“详细信息”单元格仅显示相同的值?(如果是这样,可能是因为您正在从
MainVC
DetailVC
传递相同的数据,
let shot=shots[sItem[0]。row]
可能是问题所在)此代码不起作用,因为您无法将类型“[shot]”的值分配给类型“shot!”您的detailVC中的数据源是如何建模的?该变量是一个
Shot
数组还是一个
Shot
变量?如果它只是一个变量,那么获取选定单元格没有意义。您应该将逻辑移动到
didSelectRowAtIndexPath
,获取所选单元格的
indexPath
,然后将其分配给变量,然后
performsguewithindentifer
。答案已更新
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
            }

        }
    }