UITableView实用技巧

作者: FlyElephant | 来源:发表于2016-05-11 18:23 被阅读98次

    1.去除多余的空白单元格,当UITableView的单元格较少,UITableView空白处会出现多余的单元格:
    <pre><code>
    self.tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];</code></pre>
    2.UITableViewCell设置选中状态时的视图:
    <pre><code>UIImageView *checkView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 1, 27, 27)]; checkView.image = [UIImage imageNamed:@"FlyElephant"]; cell.accessoryView = checkView;</code></pre>
    3.单元格选中无选中色:
    <pre><code>cell.selectionStyle = UITableViewCellSelectionStyleNone;</code></pre>
    4.设置分割线位置:
    <pre><code>`-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    // Remove seperator inset
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
    [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    
    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    

    }`</code></pre>

    5.UITableView中设置tableFooterView之后,最后一行的分割线会被隐藏,可以通过下面的方法设置:
    <pre><code>- (void)layoutSubviews { [super layoutSubviews]; for (UIView *subview in self.contentView.superview.subviews) { NSString *subCls=NSStringFromClass(subview.class); if ([subCls hasSuffix:@"SeparatorView"]) { subview.hidden = NO; } } }</code></pre>

    相关文章

      网友评论

        本文标题:UITableView实用技巧

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