我使用以下方法删除表格单元格,但它不会使在该单元格内运行的计时器无效。
[tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationBottom];
答案 0 :(得分:0)
Here's what I would do instead:
First, I would ensure each cell has a unique identifier of some sort. Then, I would create an NSMutableArray or NSMutableDictionary as a property of your UIViewController that stores each cell's corresponding NSTimer. Next, if a reference to the NSTimer from a table view cell is absolutely necessary, I can create a weak reference to the NSTimer in the dictionary. Then, when I go to delete the table view cell, I can also invalidate the timer by looking it up in the NSArray/NSDictionary and then deleting it.