UIswitch in a table cell reused

前端 未结 3 1840
孤街浪徒
孤街浪徒 2021-01-25 21:46

I have a problem with uiswitch in my UITableViewCell that whenever i change a switch value in a specific cell that belongs to a specific section. All other sections

3条回答
  •  梦谈多话
    2021-01-25 22:49

    You have two main problems:

    1. This code is wrong:

        [cell addSubview:switchController ];
      

      Never add a subview to the cell; add it only to the cell's contentView.

    2. You are adding the switch every time through cellForRowAtIndexPath:. But these cells are being reused. So some cells already have the switch. Thus you are adding many switches to some cells.

提交回复
热议问题