AKPickerView-Swift icon indicating copy to clipboard operation
AKPickerView-Swift copied to clipboard

Selected Item Highlight Text

Open scott-sherwood opened this issue 9 years ago • 5 comments

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?

scott-sherwood avatar Jan 02 '16 12:01 scott-sherwood

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?

keylook avatar Feb 02 '16 09:02 keylook

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. :)

simonarcher avatar Apr 13 '16 16:04 simonarcher

Same problem here, @simonarcher your solution worked!

nicotroia avatar Jun 07 '16 08:06 nicotroia

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

nefarianblack avatar Oct 13 '16 09:10 nefarianblack

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

ionutale avatar Oct 25 '17 13:10 ionutale