iOS 13 UISegmentedControl sets selected index to -1 if segments are changed

Originator:m
Number:rdar://6654384 Date Originated:2019-07-13
Status:Closed Resolved:2019-08-29
Product:UIKit Product Version:13.0
Classification:Bug Reproducible:Always
 
Basic Information
Please provide a descriptive title for your feedback:

iOS 13 UISegmentedControl sets selected index to -1 if segments are changed

Which area are you seeing an issue with?
UIKit

What type of feedback are you reporting?
Incorrect/Unexpected Behavior

Description
Please describe the issue and what steps we can take to reproduce it:
I have some code which:
- removes all segments from an existing UISegmentedControl
- adds new segments
- sets the selectedSegmentIndex

This works fine in iOS 12, but for iOS 13 the index is set to -1 _after_ I set my intended selected index.

(Tested this by adding KVO to the “selectedSegmentIndex” property)

I’m doing all my changes on the main thread. 

This is a change from iOS 12, where my selected index is not overwritten. 

Result: the UISegmentedControl behaves like it’s in “momentary” mode. (It’s not)

Comments

Resolved in iOS 13.0 beta 8


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!