Hello Readers,
In case you want to start a table view from the bottom of the screen rather than the top of the screen, you may call the following method from the delegate method as follows:
- (void)updateCellInset {
NSInteger numRows=[self tableView:_tableView numberOfRowsInSection:0];
CGFloat contentInsetTop=_tableView.bounds.size.height;
for (int i=0;i<numRows;i++) {
contentInsetTop-=[self tableView:_tableView heightForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
if (contentInsetTop<=0) {
contentInsetTop=0;
break;
}
}
_tableView.contentInset = UIEdgeInsetsMake(contentInsetTop, 0, 0, 0);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
[self updateCellInset];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return value;
}
0 Comment(s)