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
To set the height for row you need to set
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return rowHt[indexPath.row];
}
The each row can have different height only if you set it at
heightForRowAtIndexPath
for that you need to select the corresponding rows from
indexPath.row
If you are setting your tabelView from code it would look something like this
@property(nonatomic, strong) UITableView *table_sender;
self.table_sender = [[UITableView alloc] initWithFrame:frameTable style:UITableViewStylePlain] ;
self.table_sender.dataSource = self;
self.table_sender.delegate = self;
where rowHt is a array of collection of height for each rows
if you are using AutoLayout then you can't set frames - if you do that you get wiered behaviour
Autolayout is sort of relative approach of placing UI components on screen. For e.g Stand 100px behind me and 20px from left boundary (here i have used pixel - you can think of as meters think of it as playground)
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] ;
}
}