When a UITableView initially displayed, it calls this method once for each row
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
after that, the method is called when a new line is required, which is often the result of scrolling to show a new line and pressing the old view from the other end.
So this is the perfect hook to find out which lines are visible. To check which cells are visible, you can call
- (NSArray *)indexPathsForVisibleRows
Since tableview is the only thing that contains a link to your cells, before they are processed or freshly prepared, you will not be able to access these timers. I suggest creating an NSMutableDictionary ivar, and when you create your cells add a timer to NSMutableDictionary
[timersForIndexs setObject:yourTimer forKey:indexPath]
Now that you get - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath , you need to do something like
NSMutableDictionary *tmpDictionary = [timersForIndexs copy]; [tmpDictionary removeObjectsForKeys:[self.tableView indexPathsForVisibleRows]]; NSArray *timers = [tmpDictionary allKeys]; [timers makeObjectsPerformSelector:@selector(invalidate)];
I am not in front of xcode, so this is dry encoding, so please let me know if you have any problems.
Paul.s
source share