From f6689164d6785ea6f84fca96a51e8d681bd105db Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 21 Oct 2015 13:43:33 +0800 Subject: [PATCH] better definition of userMode in DiscoverViewController --- .../Discover/DiscoverViewController.swift | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Yep/ViewControllers/Discover/DiscoverViewController.swift b/Yep/ViewControllers/Discover/DiscoverViewController.swift index 613ed0e3..80fac373 100644 --- a/Yep/ViewControllers/Discover/DiscoverViewController.swift +++ b/Yep/ViewControllers/Discover/DiscoverViewController.swift @@ -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) } - } -