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;
}