UISegmentedControl -setX:forSegmentAtIndex: does not pin to range

Originator:chaos42
Number:rdar://14692011 Date Originated:08-Aug-2013 04:56 PM
Status:Open Resolved:
Product:iOS SDK Product Version:6.1/10B141
Classification:Other Bug Reproducible:Always
 
Summary:
UISegmentedControl's -setImage:forSegmentAtIndex: and -setTitle:forSegmentAtIndex: are documented to behave as follows: "An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it." However this is not true. Instead, an exception is thrown.

Steps to Reproduce:
1. create a new iOS application in Xcode 4.6.3 and paste the following lines into -application:didFinishLaunching:withOptions: just after creating the window. 

    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Foo", @"Bar", @"Baz"]];
    [segmentedControl setTitle:@"Qux" forSegmentAtIndex:10];
    NSLog(@"segment titles: %@, %@, %@", [segmentedControl titleForSegmentAtIndex:0], [segmentedControl titleForSegmentAtIndex:1], [segmentedControl titleForSegmentAtIndex:2]);

2. Run the project

Expected Results:
The Baz label should be replaced with a Qux label.

Actual Results:
The application crashes due to an NSRangeException exception. 

Regression:
Unknown

Notes:
Possibly a documentation bug. Workaround: pin to the range yourself before calling.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!