美文网首页
关于ios UITableView 重用 不只是cell

关于ios UITableView 重用 不只是cell

作者: songsongchen | 来源:发表于2016-02-17 10:30 被阅读499次

    UITableView

    我们知道cell 可以根据标记Identifier 可以进行重用,节省内存。

    但是我们很多时候 我们在设置 headerView  FootView 的时候 就是没有用到重用了!每次都是初始化了。但iOS中在6.0的时候就推出了重用的机制

    所以我们在使用UItTableView时候,可以不只是对cell进行重用,还有headerView  FootView

    例子:

    -(UIView*)tableView:(UITableView*)tableView  viewForHeaderInSection:(NSInteger)section

    {

    UILabel*titleLabel = [[UILabel  alloc]init];

    titleLabel.frame= CGRectMake(5,0,200,30);

    titleLabel.textColor= [UIColor  purpleColor];

    titleLabel.text=@"xixi";

    returntitleLabel;

    }

    重用

    -(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section

    {

    static   NSString   *headerSectionID =@"cityHeaderSectionID";

    UITableViewHeaderFooterView  *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerSectionID];

    if(headerView ==nil)

    {

    headerView = [[UITableView HeaderFooterViewalloc] initWithReuseIdentifier:headerSectionID];

    UILabel*titleLabel = [[UILabel alloc] init];

    titleLabel.frame= CGRectMake(5,0,200,30);

    titleLabel.textColor= [UIColor  purpleColor];

    titleLabel.tag=100;

    [headerView  addSubview:titleLabel];

    }

    returnheaderView;

    }

    UITableView用法分享 感谢楼主LC

    相关文章

      网友评论

          本文标题:关于ios UITableView 重用 不只是cell

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