better definition of userMode in DiscoverViewController

This commit is contained in:
nixzhu
2015-10-21 13:43:33 +08:00
committed by nixzhu
parent 7242dfb387
commit f6689164d6
@@ -29,14 +29,16 @@ class DiscoverViewController: BaseViewController {
let CardUserIdentifier = "DiscoverCardUserCell"
var userMode: DiscoverUserMode? {
var userMode: DiscoverUserMode = .Card {
didSet {
layout.userMode = userMode
switch userMode! {
switch userMode {
case .Card:
view.backgroundColor = UIColor.yepBackgroundColor()
modeButtonItem.image = UIImage(named: "icon_list")
case .Normal:
view.backgroundColor = UIColor.whiteColor()
modeButtonItem.image = UIImage(named: "icon_minicard")
@@ -141,7 +143,8 @@ class DiscoverViewController: BaseViewController {
// MARK: Actions
@IBAction func changeMode(sender: AnyObject) {
switch userMode! {
switch userMode {
case .Card:
userMode = .Normal
@@ -199,24 +202,20 @@ class DiscoverViewController: BaseViewController {
extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return discoveredUsers.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
// let discoveredUser = discoveredUsers[indexPath.row]
switch userMode! {
switch userMode {
case .Normal:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(NormalUserIdentifier, forIndexPath: indexPath) as! DiscoverNormalUserCell
// cell.configureWithDiscoveredUser(discoveredUser, collectionView: collectionView, indexPath: indexPath)
return cell
case .Card:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(CardUserIdentifier, forIndexPath: indexPath) as! DiscoverCardUserCell
// cell.configureWithDiscoveredUser(discoveredUser, collectionView: collectionView, indexPath: indexPath)
return cell
}
}
@@ -224,10 +223,10 @@ extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewData
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
let discoveredUser = discoveredUsers[indexPath.row]
switch userMode! {
switch userMode {
case .Normal:
let cell = cell as! DiscoverNormalUserCell
cell.configureWithDiscoveredUser(discoveredUser, collectionView: collectionView, indexPath: indexPath)
case .Card:
@@ -237,7 +236,9 @@ extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewData
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
switch userMode! {
switch userMode {
case .Normal:
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
@@ -245,14 +246,11 @@ extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewData
return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
}
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
collectionView.deselectItemAtIndexPath(indexPath, animated: true)
performSegueWithIdentifier("showProfile", sender: indexPath)
}
}