From d41156cfcce840dba6ffc8f45d4fbb7ef52cb328 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 24 Jul 2015 11:59:08 +0800 Subject: [PATCH] add SkillCell.Skill for SkillHome; fix no cover skill no go to SkillHome --- .../Profile/ProfileViewController.swift | 28 ++++++---------- .../SkillHome/SkillHomeViewController.swift | 13 ++++---- Yep/Views/Cells/Skill/SkillCell.swift | 32 +++++++++++++------ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index a10dd43c..051f6a78 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -433,9 +433,7 @@ class ProfileViewController: UIViewController { vc.preferedState = SkillHomeState(rawValue: preferedState) } - vc.skillID = skillInfo["skillID"] as? String - vc.skillLocalName = skillInfo["skillLocalName"] as? String - vc.skillCoverURLString = skillInfo["skillCoverURLString"] as? String + vc.skill = skillInfo["skill"] as? SkillCell.Skill vc.afterUpdatedSkillCoverAction = { [weak self] in self?.updateProfileCollectionView() @@ -828,20 +826,16 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel switch profileUser { case .DiscoveredUserType(let discoveredUser): let skill = discoveredUser.masterSkills[indexPath.item] - cell.skillID = skill.id - cell.skillLocalName = skill.localName - cell.skillCoverURLString = skill.coverURLString + cell.skill = SkillCell.Skill(ID: skill.id, localName: skill.localName, coverURLString: skill.coverURLString) case .UserType(let user): let userSkill = user.masterSkills[indexPath.item] - cell.skillID = userSkill.skillID - cell.skillLocalName = userSkill.localName - cell.skillCoverURLString = userSkill.coverURLString + cell.skill = SkillCell.Skill(ID: userSkill.skillID, localName: userSkill.localName, coverURLString: userSkill.coverURLString) } } - cell.tapAction = { [weak self] skillID, skillLocalName, skillCoverURLString in - self?.performSegueWithIdentifier("showSkillHome", sender: ["preferedState": SkillHomeState.Master.rawValue, "skillID": skillID, "skillLocalName": skillLocalName, "skillCoverURLString": skillCoverURLString]) + cell.tapAction = { [weak self] skill in + self?.performSegueWithIdentifier("showSkillHome", sender: ["skill": skill, "preferedState": SkillHomeState.Master.rawValue]) } return cell @@ -853,20 +847,16 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel switch profileUser { case .DiscoveredUserType(let discoveredUser): let skill = discoveredUser.learningSkills[indexPath.item] - cell.skillID = skill.id - cell.skillLocalName = skill.localName - cell.skillCoverURLString = skill.coverURLString + cell.skill = SkillCell.Skill(ID: skill.id, localName: skill.localName, coverURLString: skill.coverURLString) case .UserType(let user): let userSkill = user.learningSkills[indexPath.item] - cell.skillID = userSkill.skillID - cell.skillLocalName = userSkill.localName - cell.skillCoverURLString = userSkill.coverURLString + cell.skill = SkillCell.Skill(ID: userSkill.skillID, localName: userSkill.localName, coverURLString: userSkill.coverURLString) } } - cell.tapAction = { [weak self] skillID, skillLocalName, skillCoverURLString in - self?.performSegueWithIdentifier("showSkillHome", sender: ["preferedState": SkillHomeState.Learning.rawValue, "skillID": skillID, "skillLocalName": skillLocalName, "skillCoverURLString": skillCoverURLString]) + cell.tapAction = { [weak self] skill in + self?.performSegueWithIdentifier("showSkillHome", sender: ["skill": skill, "preferedState": SkillHomeState.Learning.rawValue]) } return cell diff --git a/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift b/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift index 0ab78ec5..4a608565 100644 --- a/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift +++ b/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift @@ -31,11 +31,10 @@ class SkillHomeViewController: CustomNavigationBarViewController { return tempTableView; }() - var skillID: String? - - var skillLocalName: String? { + var skill: SkillCell.Skill? { willSet { - title = newValue + title = newValue?.localName + skillCoverURLString = newValue?.coverURLString } } @@ -124,7 +123,7 @@ class SkillHomeViewController: CustomNavigationBarViewController { learningtTableView.delegate = self learningtTableView.tag = SkillHomeState.Learning.hashValue - if let skillID = skillID { + if let skillID = skill?.ID { discoverUserBySkillID(skillID) } @@ -242,7 +241,7 @@ class SkillHomeViewController: CustomNavigationBarViewController { NSFontAttributeName: UIFont.skillHomeTextLargeFont() ] - let titleAttr = NSMutableAttributedString(string: skillLocalName ?? "", attributes:textAttributes) + let titleAttr = NSMutableAttributedString(string: skill?.localName ?? "", attributes:textAttributes) titleLabel.attributedText = titleAttr titleLabel.textAlignment = NSTextAlignment.Center @@ -369,7 +368,7 @@ extension SkillHomeViewController: UIImagePickerControllerDelegate, UINavigation let data = UIImageJPEGRepresentation(fixedImage, 0.7) - if let skillID = skillID { + if let skillID = skill?.ID { YepHUD.showActivityIndicator() diff --git a/Yep/Views/Cells/Skill/SkillCell.swift b/Yep/Views/Cells/Skill/SkillCell.swift index 5b30ee77..2fb2b0dd 100644 --- a/Yep/Views/Cells/Skill/SkillCell.swift +++ b/Yep/Views/Cells/Skill/SkillCell.swift @@ -31,15 +31,25 @@ class SkillCell: UICollectionViewCell { } } - var skillID: String? - var skillLocalName: String? { - willSet { - skillLabel.text = newValue + class Skill: NSObject { + let ID: String + let localName: String + let coverURLString: String? + + init(ID: String, localName: String, coverURLString: String?) { + self.ID = ID + self.localName = localName + self.coverURLString = coverURLString } } - var skillCoverURLString: String? - var tapAction: ((skillID: String, skillLocalName: String, skillCoverURLString: String) -> Void)? + var skill: Skill? { + willSet { + skillLabel.text = newValue?.localName + } + } + + var tapAction: ((skill: Skill) -> Void)? override func touchesBegan(touches: Set, withEvent event: UIEvent) { tapped = true @@ -48,10 +58,14 @@ class SkillCell: UICollectionViewCell { override func touchesEnded(touches: Set, withEvent event: UIEvent) { delay(0.15) { [weak self] in - self?.tapped = false - if let skillID = self?.skillID, skillLocalName = self?.skillLocalName, skillCoverURLString = self?.skillCoverURLString { - self?.tapAction?(skillID: skillID, skillLocalName: skillLocalName, skillCoverURLString: skillCoverURLString) + if let strongSelf = self { + + strongSelf.tapped = false + + if let skill = strongSelf.skill { + strongSelf.tapAction?(skill: skill) + } } } }