Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView/UIScrollView how to automatically know when ContentSize changes?

Tags:

Is there an automatic way to be aware of a ContentSize changes in a UITableView/UIScrollView?

like image 899
philouuuu Avatar asked Jul 02 '12 21:07

philouuuu


1 Answers

The answer is actually simple using KVO (Key Value Observing);

- (id)initWithFrame:(CGRect)frame tableView:(UITableView *)tableView {     // ....     [self.tableView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld | NSKeyValueObservingOptionPrior context:NULL];     // .... }  - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context  {     if ([keyPath isEqualToString:@"contentSize"])      {         // Do something     } } 

I am not sure about the flags yet though.

like image 92
philouuuu Avatar answered Mar 06 '23 08:03

philouuuu