嗨,大家好所以最近出現了從運球獲取數據的錯誤..運球阿比返回錯誤的數據
我Dribbble客戶端IOS顯示在主屏幕上的鏡頭,如果你點擊一個細胞的CollectionView它把你帶到拍攝的細節..
而我通過這個方法通過它的api獲取Dribble數據。
的代碼的方法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 =鏡頭線它返回像這樣..
The log when debugging on the self.shots = shots line
這一切工作正常..以及類Shot的詳細的代碼... 我一直在使用動態的tableView以顯示拍攝詳細
在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
}
}
和守則的射擊類..我從哪裏得到的所有數據設置爲標籤
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)
}
}
}
現在概率當我點擊單元格以進入下一個單元格時發生lem。 之前,如果我在射擊類調試..
的數據看起來像這樣
The Log Which shows the data returned
,現在每當我點擊單元格。去細節。該數據返回只有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個鏈接。
任何幫助將是非常讚賞..
感謝 雅利安
你的問題是十分含糊,包括不必要的代碼了很多。你能截斷這一點並指出具體問題嗎? – kye
我已經減少它@kye,如果你認爲它應該更多減少請讓我知道.. –
它可能仍然會減少一點(它需要很多代碼)。究竟是什麼問題?細節單元格只顯示相同的值? (如果是這樣,可能是因爲你將相同的數據從你的'MainVC'傳遞給'DetailVC','let shot = shots [sItem [0] .row]'可能是問題) – kye