iOS Question Crash in Picker GetSelectedItem(0) with IOS13

marcick

Well-Known Member
Licensed User
Longtime User
Hi all, I'm having problem after an IOS 13 update.

I populate a picker with a list of items

B4X:
Dim items As List
items.Initialize
items.Add("one")
items.Add("two")
items.Add("three")
items.Add("four")
Pckr1.SetItems(0, items)

Now I choose the last item in the picker.
If I log(Pckr1.GetSelectedItem(0)) I correctly have "four"
Now I want to delete this last item

B4X:
Dim items as list
items.initialize2(Pckr1.GetItems(0))
items.RemoveAt(items.IndexOf(Pckr1.GetSelectedItem(0)))
Pckr1.SetItems(0,lls)

IOS12: If I log(Pckr1.GetSelectedItem(0)) I correctly have "three"
IOS13: If I log(Pckr1.GetSelectedItem(0)) .... crash

B4X:
*** -[__NSArrayM objectAtIndexedSubscript:]: index 4 beyond bounds [0 .. 3]

Is my method to remove the last item in the picker incorrect ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Found it.

In IOS 12, removing the last items in the picker, the selected item is automatically set to the prevoious.

In IOS13, after removing the items, a SelectRow is needed

B4X:
....
items.RemoveAt(items.IndexOf(Pckr1.GetSelectedItem(0)))
Pckr1.SetItems(0,items)
Pckr1.SelectRow(0,items.size-1, False)
 
Upvote 0
Top