Skip to content

Disable Segement should add check selectedSegmentIndex #63

@xrksudy

Description

@xrksudy

When I run SDSegmentedControl Demo, I try click Disable Segement Button, At last, The app will crash. I found this code don't check selectedSegmentIndex.

  • (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)index
    {
    [self segmentAtIndex:index].enabled = enabled;

    if (index == self.selectedSegmentIndex)
    {
    self.selectedSegmentIndex = [self firstEnabledSegmentIndexNearIndex:index];
    }
    }

The Demo App Crash Log is:

2013-11-11 23:11:46.110 Example[70636:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: index >= 0 && index < self._items.count'
*** First throw call stack:
(
0 CoreFoundation 0x01b195e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x017088b6 objc_exception_throw + 44
2 CoreFoundation 0x01b19448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x010dbfee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 Example 0x0000745b -[SDSegmentedControl segmentAtIndex:] + 363
5 Example 0x00006305 -[SDSegmentedControl setEnabled:forSegmentAtIndex:] + 69
6 Example 0x000033af -[ViewController disableSegment:] + 191
7 libobjc.A.dylib 0x0171a874 -[NSObject performSelector:withObject:withObject:] + 77
8 UIKit 0x0026b0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
9 UIKit 0x0026b04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
10 UIKit 0x003630c1 -[UIControl sendAction:to:forEvent:] + 66
11 UIKit 0x00363484 -[UIControl _sendActionsForEvents:withEvent:] + 577
12 UIKit 0x00362733 -[UIControl touchesEnded:withEvent:] + 641
13 UIKit 0x002a851d -[UIWindow _sendTouchesForEvent:] + 852
14 UIKit 0x002a9184 -[UIWindow sendEvent:] + 1232
15 UIKit 0x0027ce86 -[UIApplication sendEvent:] + 242
16 UIKit 0x0026718f _UIApplicationHandleEventQueue + 11421
17 CoreFoundation 0x01aa283f CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15
18 CoreFoundation 0x01aa21cb __CFRunLoopDoSources0 + 235
19 CoreFoundation 0x01abf29e __CFRunLoopRun + 910
20 CoreFoundation 0x01abeac3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x01abe8db CFRunLoopRunInMode + 123
22 GraphicsServices 0x031689e2 GSEventRunModal + 192
23 GraphicsServices 0x03168809 GSEventRun + 104
24 UIKit 0x00269d3b UIApplicationMain + 1225
25 Example 0x000022cd main + 141
26 Example 0x00002235 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException

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