返回每行的單元格
你選擇的自定義的cell拼接id移宅,以此cell名稱去創(chuàng)建靜態(tài)變量拴袭。放在下方的
static NSString * const CourseDetailCommentTableViewCellID = @"CourseDetailCommentTableViewCell";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
由于此方法調(diào)用十分頻繁,cell的標(biāo)示聲明成靜態(tài)變量有利于性能優(yōu)化
static NSString *cellIdentifier=@"UITableViewCellIdentifierKey1";
//首先根據(jù)標(biāo)識(shí)去緩存池取
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//如果緩存池沒有到則重新創(chuàng)建并放到緩存池中
if(!cell){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
return cell;
}
如何高效的快速創(chuàng)建tableviewcell沽损,且細(xì)節(jié)完美渐排。
11EDB0CB-102D-46ED-8823-065C73645926.png
HealthSubscribeThreeImageTableViewCell.m
static NSString * const HealthSubscribeThreeImageTableViewCellID = @"HealthSubscribeThreeImageTableViewCell";
+ (instancetype)cellWithTableView:(UITableView *)tableView {
HealthSubscribeThreeImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HealthSubscribeThreeImageTableViewCellID];
if (cell == nil) {
cell = [[[UINib nibWithNibName:NSStringFromClass(self) bundle:nil] instantiateWithOwner:nil options:nil] objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
}
在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 這樣寫屈暗。
HealthSubscribeThreeImageTableViewCell *cell = [HealthSubscribeThreeImageTableViewCell cellWithTableView:tableView]; return cell;
且Xib創(chuàng)建用NIb加載會(huì)比bundle性能高。
http://www.reibang.com/p/2f9e71ef7f52
XIb一定不要忘記重用符
719DA4D2-1443-4CDE-A9DC-D4BFF6094B73.png
如何設(shè)置tableviewCell兩者間的間隙:
-
(void)setFrame:(CGRect)frame{
frame.origin.y+=10;
frame.size.height-=10;
[super setFrame:frame];
}
西藥_PxCook.png