Skip to content

Deselecting all Items hangs in assertion #8

@Oggerschummer

Description

@Oggerschummer

* Just saw this might be a duplicate, sorry - newbie failure*

Hi,

just checked out this nice piece of code (thanks !) and ran into an issue.
I rely on the ability to deselect all segments in the segemented control.
For UISegmentedControl this is possible by setting the selectedSegmentIndex to -1.

URBSegmentedControl has some checks in

- (void)setSelectedSegmentIndex:(NSInteger)selectedSegmentIndex

that do not allow -1 as a value.

Tried the following change as a quick and dirty hack:

//NSParameterAssert(selectedSegmentIndex < (NSInteger)self.items.count && selectedSegmentIndex >= 0);
    //20130326 OGGERSCHUMMER fix for unselected control
    NSParameterAssert(selectedSegmentIndex < (NSInteger)self.items.count && selectedSegmentIndex >= -1);

    // deselect current segment if selected
    if (_selectedSegmentIndex >= 0)
        ((URBSegmentView *)[self segmentAtIndex:_selectedSegmentIndex]).selected = NO;
    if (selectedSegmentIndex>=0){//20130326 OGGERSCHUMMER Handle deselection of everything
        [self segmentAtIndex:selectedSegmentIndex].selected = YES;
    }

...

From what I see this does the trick, but I don´t know your code in detail yet.

Maybe you can check and adjust this.

Cheers,
Oggerschummer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions