开发者

Get state of UISwitch in custom UITableViewCell's

I am using a custom tableviewcell in one of my view's. I have decided to add a UISwitch to this cell to enable the user to delete multiple row's at once.

Normally when the user selects a row and taps my delete button I have a UIAlert pop up for confirmation and after that the alert clickedButtonAtIndex method handles the outcome. In that method I get the indexpath ( [self.myTableView indexPathForSelectedRow] ) and delete (or not) accordingly.

So basically as the title states instead of using the indexPath to fall into my delete statement, I need to check to see if self.myTableView.myCell.mySwitch.on is TRUE. Can anyone point me in the right direction for doing this? I will need to 开发者_开发技巧iterate through all rows in the tableview and for each row where the state is on it needs to be removed.

Thanks.


you should iterate through your cells using a nested loop ( or a single loop if you have only one section) and cellForRowAtIndexPath:.
if you see a cell's switch.on = TRUE save it's indexPath in an array by calling indexPathForCell:.
after you're done iterating through your cells, call deleteRowsAtIndexPaths:withRowAnimation: with the array previously created.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜