Fix crash when setting selectedIndex before view appears.