fill dribbbleShots to dribbbleCollectionView

This commit is contained in:
nixzhu
2015-05-13 03:02:45 +08:00
parent 88cc2ecaf0
commit 9ce93c8daa
3 changed files with 23 additions and 2 deletions
@@ -7,6 +7,7 @@
//
import UIKit
import Kingfisher
class SocialWorkDribbbleViewController: UIViewController {
@@ -21,6 +22,12 @@ class SocialWorkDribbbleViewController: UIViewController {
return CGRectGetWidth(self.dribbbleCollectionView.bounds)
}()
var dribbbleShots = Array<DribbbleWork.Shot>() {
didSet {
updateDribbbleCollectionView()
}
}
override func viewDidLoad() {
super.viewDidLoad()
@@ -48,12 +55,20 @@ class SocialWorkDribbbleViewController: UIViewController {
}, completion: { dribbbleWork in
println("dribbbleWork: \(dribbbleWork.shots.count)")
dispatch_async(dispatch_get_main_queue()) {
self.dribbbleShots = dribbbleWork.shots
}
})
}
}
// MARK: Actions
func updateDribbbleCollectionView() {
dribbbleCollectionView.reloadData()
}
func gotoUserDribbbleHome() {
// TODO: gotoUserDribbbleHome
}
@@ -67,14 +82,16 @@ extension SocialWorkDribbbleViewController: UICollectionViewDataSource, UICollec
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 30
return dribbbleShots.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(dribbbleShotCellIdentifier, forIndexPath: indexPath) as! DribbbleShotCell
cell.imageView.image = UIImage(named: "Cover3")
let shot = dribbbleShots[indexPath.item]
cell.imageView.kf_setImageWithURL(NSURL(string: shot.images.normal)!)
return cell
}