yonat / MultiSelectSegmentedControl

UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

initSortedSegmentsArray fails when MultiSelectSegmentedControl was created with Storyboard

chrizztus opened this issue · comments

When I create a MultiSelectSegmentedControl using Storyboard from Xcode (4.6.2) the segments of the MultiSelectSegmentedControl won't be sorted (or can't be).

The initial origin x values from sortedSegments array are either 0 or -1. My assumption is that the segmented control created with Storyboard is handled on a different way from xib files.

My current workaround is to sort the segmentsArray again when the valueChanged method is called for the first time. At this time the origin x values are different from 0 or -1 and can be sorted as intended.

Thanks!

chrizztus wrote:

When I create a MultiSelectSegmentedControl using Storyboard from Xcode
(4.6.2) the segments of the MultiSelectSegmentedControl won't be sorted
(or can't be).

The initial origin x values from sortedSegments array are either 0 or
-1. My assumption is that the segmented control created with Storyboard
is handled on a different way from xib files.

My current workaround is to sort the segmentsArray again when the
valueChanged method is called for the first time. At this time the
origin x values are different from 0 or -1 and can be sorted as intended.


Reply to this email directly or view it on GitHub
#1.

Maybe consider updating MultiSelectSegmentedControl and just change the valueChanged method to the code below as mentioned by chrizztus. Makes it easier to implement for us noobs :) or just mention it in the README would be good enough imo.

  • (void)valueChanged
    {
    //needed for storyboards
    [self initSortedSegmentsArray];

    NSUInteger tappedSegementIndex = super.selectedSegmentIndex;
    if ([self.selectedIndexes containsIndex:tappedSegementIndex]) {
    [self.selectedIndexes removeIndex:tappedSegementIndex];
    }
    else {
    [self.selectedIndexes addIndex:tappedSegementIndex];
    }
    [self selectSegmentsOfSelectedIndexes];
    }

Just pushed the fix suggested by chrizztus.