Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Selected Item Highlight Text #35

Open
scott-sherwood opened this issue Jan 2, 2016 · 5 comments
Open

Selected Item Highlight Text #35

scott-sherwood opened this issue Jan 2, 2016 · 5 comments

Comments

@scott-sherwood
Copy link

The highlightedFont is set to bold. However, when you select another item the previous item remains bold and the new item's font does not become bold. When the first item is scrolled off the screen it is redrawn and the font is set to the system font rather than the bold font.

It would appear that the issue is with the selected implementation of the AKCollectionViewCell. Changing this from _selected to selected removing the initialisation to false and updating the setting in the cellForRowAtIndexPath fixed the issue for me.

Has anyone else had this issue? Could it be the way I am initialising the picker or is this a genuine issue others have experienced?

@keylook
Copy link

keylook commented Feb 2, 2016

Hey.
I've had the same struggle, that's why I came to the thread.

There was a notice in the readme file, that you have to call pickerView.reloadData() whenever you change its settings. Solved the issue for me.

Still has a problem like all the reload methods do. The view blinks to redraw. This blink also takes away the swiping animation so I guess calling the reload method is not the best solution here.

Can you please show your solution?

@simonarcher
Copy link

Came here for the same issue.

Based on Scott mentioned, I think I manage to replicate his solution...

In the AKPickerView.swift file, find the private class AKCollectionViewCell : UICollectionViewCell initialisation (line 57 for me)
Where you see var _selected : Bool = false {...} I changed it to

override var selected: Bool  {
        didSet(selected) {
            let animation = CATransition()
            animation.type = kCATransitionFade
            animation.duration = 0.15
            self.label.layer.addAnimation(animation, forKey: "")
            self.label.font = self.selected ? self.highlightedFont : self.font
        }
    }

Then further down in the public func collectionView( cellforItemAtInexPath) (line 518 for me) you will see an error with cell._selected = (indexPath.item == self.selectedItem).
I just then update cell._selected with the new cell.selected

Built the code, and now it seems to be behaving as expected. :)

@nicotroia
Copy link

Same problem here, @simonarcher your solution worked!

@nefarianblack
Copy link

Also note: call .selectItem(index, animated: false) in viewDidLoad. This including changes mentioned above did the trick for me.

fwaddle added a commit to fwaddle/AKPickerView-Swift that referenced this issue Jan 13, 2017
@ionutale
Copy link

this is still not fixed, i am struggling on finding a fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants