iOS的tableViewCell自适应

首先,你一定会创建好ViewController 和tableViewCell的类文件。

那在tableViewCell。h中写好声明用到的属性,如图1.

如图1 。h文件中的声明

然后是在。m中写好计算cell高度的方法,如图2.

如图2.m文件中的计算方法

接下来就是回到Viewontroller中在tableview的协议方法中调用方法。

通过-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;方法,如图3.

如图3 heightForRowAtIndexPath方法

然后再根据用到的协议方法编写,

1、- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

2、- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

3、- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

4、- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

5、- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectio;

等等。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容