How to reset cellview cellview element not show at the click of a button?

I am trying to encode a reset button, so when I click on this button, all the tableview type accessory get none .

I have a clear idea of ​​how to do this, but I'm pretty new to iPhone development, so I just need help with which methods to call.

The steps that I think I need to take: I repeat all the lines using the for loop, so I count the number of cells (successfully completed). My problem is that I do not know how to check each of these rows / cells if the accessory type is CheckMark and set it to none .

Alternatively, I can set all my cells to AccessoryNone , but I already do some calculations inside:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

Therefore, I am not sure how I can achieve this.

+4
source share
2 answers

No need to check what accessoryType , just assign a UITableViewCellAccessoryNone all of them. This should work on what you are trying to do:

 // replace clickedResetButton with your action handler method for that button - (IBAction)clickedResetButton:(id)sender { for (int section = 0, sectionCount = self.tableView.numberOfSections; section < sectionCount; ++section) { for (int row = 0, rowCount = [self.tableView numberOfRowsInSection:section]; row < rowCount; ++row) { UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]]; cell.accessoryType = UITableViewCellAccessoryNone; cell.accessoryView = nill; } } } 
+10
source

Swift 3.1

 func resetAccessoryType(){ for section in 0..<self.tableView.numberOfSections{ for row in 0..<self.tableView.numberOfRows(inSection: section){ let cell = self.tableView.cellForRow(at: IndexPath(row: row, section: section)) cell?.accessoryType = .none } } } 
0
source

Source: https://habr.com/ru/post/1379897/


All Articles