`
jsntghf
  • 浏览: 2482496 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

根据UITableView的行数动态调整UITableView的高度

    博客分类:
  • iOS
阅读更多

1、在viewDidLoad中添加观察者

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

 

2、重写observeValueForKeyPath方法,一旦UITableView的contentSize发生改变,就会调用这个方法

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    CGRect frame = self.tableView.frame;
    frame.size = self.tableView.contentSize;
    self.tableView.frame = frame;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics