Dynamic height of table is not set

前端 未结 3 1519
迷失自我
迷失自我 2021-01-21 22:28

I am trying to set dynamic height of table. But it is not working when I log height of table it is showing me dynamic height but not set to actual table.

Here is my code

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-21 23:17

    I think there must be some other code change your tableView's frame.

    Use KVO to detect change of the frame of UITableView.

    1、add an observer to it in you viewDidLoad method

    [table_sender addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil] ;
    

    2、implement observeValueForKeyPath method and add an breakpoint in it. When the breakpoint stop, check the call stack to find who change the frame.

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
    {
        if ([keyPath isEqualToString:@"frame"]) {
            NSLog(@"%@", change) ; // add an breakpoint here
        } else {
            [super observeValueForKeyPath:keyPath ofObject:object change:change context:context] ;
        }
    }
    

提交回复
热议问题