How can I get index path of cell on switch change event in section based table view

前端 未结 3 1376
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 19:47

I have custom cell having switch in few cells at right side. what I want is to store value of specific cell on switch change event. Table view has number sections so I can\'

3条回答
  •  暖寄归人
    2020-12-03 20:42

    You can still create tags even if you have sections if you have some idea of about max rows in a largest section. For example if you think there will be 1000 rows in a section then you can create tag using following formula.

    tag = section * 1000 + row;
    

    later in your IBAction of switch you can find out the indexpath (section and row) using following:

    section = tag/1000;
    row = tag%1000;
    

    If you have no idea of how many rows your section will have you can find out the cell using sender.superview.superview (be careful if have added any other views in hierarchy).

    Rory McKinnel's answer is still the cleanest solution for your problem.

提交回复
热议问题