美文网首页
UITableView

UITableView

作者: Elvist | 来源:发表于2016-06-29 16:45 被阅读39次

1. 设置TableView Separatorinset 分割线从边框顶端开始

//- (void)layoutSubviews
- (void)viewDidLayoutSubviews
{
    //[super layoutSubviews];
    [super viewDidLayoutSubviews];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {
        
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat
{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}

2. tableView滚动到底部,及是否有动画效果

- (void)tableViewScrollToBottomWithAnimation:(BOOL)animation
{
    NSUInteger section = 0;
    if (self.tableView.dataSource && [self.tableView.dataSource respondsToSelector:@selector(numberOfSectionsInTableView:)]) {
        
        section = [self.tableView.dataSource numberOfSectionsInTableView:self] - 1;
    }
    if ([self.tableView.dataSource respondsToSelector:@selector(tableView:numberOfRowsInSection:)]) {
        
        NSUInteger row = [self.tableView.dataSource tableView:self numberOfRowsInSection:section];
        if (row > 0) {
            
            [self scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:row - 1 inSection:section] atScrollPosition:UITableViewScrollPositionBottom animated:animation];
//            [self scrollRectToVisible:CGRectMake(0, self.tableView.contentSize.height - self.tableView.height, self.tableView.width, self.tableView.height) animated:animation];
        }
    }
}

相关文章

网友评论

      本文标题:UITableView

      本文链接:https://www.haomeiwen.com/subject/xsdxjttx.html