There is a table with two lists of string arrays between which we switch by means of a segment controller. for example

let standingExersiseName = ["Один", "Два", "Три", "Четыре ", "Пять"] let sittingExersiseName = ["Одинажды", "Дважды", "Трижды"] 

In these two lists, the number of elements in the array is different. When you click on a cell (and transfer to another controller) from the list with a large number of elements and the sequence number is larger than the elements in the second list (for example, click on the "Four" cell), an error fatal error occurs: Index out of range. How can this be corrected without adding to the second list the missing number of elements equal to the number from the first list?

enter image description here

    2 answers 2

    The logic of your actions is not entirely clear, but if you correct the current situation and leave everything as it is, you can:

    let nameSitting = sittingExersiseName[indexpath.row % sittingExersiseName.count]

    In general, you need to pass the index for the second table necessary, and not from the first for everything.

    • Thanks, that is necessary - Artur Skachkov

    Do not forget to do reloadData after switching a segment of the Control. And in all methods for the table, use the selected array.