preparedSkill for newFeed, but only use when I have it also

This commit is contained in:
nixzhu
2015-10-23 17:41:05 +08:00
parent 5ff7937dc4
commit b04403debb
2 changed files with 25 additions and 2 deletions
@@ -210,6 +210,8 @@ class FeedsViewController: UIViewController {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("NewFeedViewController") as! NewFeedViewController
vc.preparedSkill = skill
vc.afterCreatedFeedAction = { [weak self] feed in
dispatch_async(dispatch_get_main_queue()) {
@@ -62,6 +62,7 @@ class NewFeedViewController: UIViewController {
return []
}()
var preparedSkill: Skill?
var pickedSkill: Skill? {
willSet {
pickedSkillLabel.text = newValue?.localName
@@ -101,6 +102,11 @@ class NewFeedViewController: UIViewController {
// pick skill
// 使
if let skill = preparedSkill, _ = skills.indexOf(skill) {
pickedSkill = preparedSkill
}
channelLabel.text = NSLocalizedString("Channel:", comment: "")
choosePromptLabel.text = NSLocalizedString("Choose...", comment: "")
@@ -108,8 +114,9 @@ class NewFeedViewController: UIViewController {
skillPickerView.alpha = 0
pickedSkillBubbleImageView.alpha = 0
pickedSkillLabel.alpha = 0
let hasSkill = (pickedSkill != nil)
pickedSkillBubbleImageView.alpha = hasSkill ? 1 : 0
pickedSkillLabel.alpha = hasSkill ? 1 : 0
channelView.backgroundColor = UIColor.whiteColor()
channelView.userInteractionEnabled = true
@@ -161,12 +168,26 @@ class NewFeedViewController: UIViewController {
func showSkillPickerView(tap: UITapGestureRecognizer) {
// show selectRow
if pickedSkill == nil {
if !skills.isEmpty {
let centerRow = max / 2
skillPickerView.selectRow(centerRow, inComponent: 0, animated: false)
pickedSkill = skills[centerRow % skills.count]
}
} else {
if let skill = preparedSkill, let index = skills.indexOf(skill) {
var selectedRow = max / 2
selectedRow = selectedRow - selectedRow % skills.count + index
skillPickerView.selectRow(selectedRow, inComponent: 0, animated: false)
pickedSkill = skills[selectedRow % skills.count]
}
preparedSkill = nil // show selectRow
}
UIView.animateWithDuration(0.25, delay: 0.0, options: .CurveEaseInOut, animations: { [weak self] in