您的位置:首页 > 产品设计 > UI/UE

UITableView的使用

2015-11-17 21:33 405 查看

UITableView的使用

在使用tableview时注意以下几点:

1、需要在自定义cell里面写以下代码初始化

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) <span style="font-family: Arial, Helvetica, sans-serif;">           </span>
[self p_setupViews];// 布局,写在下面
}
return self;
}


2、 自定义cell 的高度

+(CGFloat)MusicListcellHeight;// 在cell.m文件里
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath // 这个方法写在controller的cell高度里
{
return [MusicCell MusicListcellHeight];
}


3、 cell的注册 这个经常忘 不注册的话会报错

'unable to dequeue a cell with identifier musiccell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
[self.tableView registerClass:[MusicCell class] forCellReuseIdentifier:@"musiccell"];



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: