11 Mar 2017

Dynamic Table View height based on ContentSize of table view...



Dynamic Table View height based on ContentSize of table view...


Add an Observer at which situation you want to maintain dynamic height for tableview...

 [self.searchTableView addObserver:self forKeyPath:@"contentSize" options:0 context:NULL];




- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

{
    if (self.searchTableView.contentSize.height < 250) {
         self.searchTableView.frame = CGRectMake(self.searchBar.frame.origin.x, self.searchBar.frame.origin.y+44, self.searchTableView.frame.size.width,self.searchTableView.contentSize.height);

//    CGRect frame = self.searchTableView.frame;
//    frame.size = self.searchTableView.contentSize;
//    self.searchTableView.frame = frame;

    }
   
}

No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0