美文网首页
iOS的tableViewCell自适应

iOS的tableViewCell自适应

作者: 肉肉要次肉 | 来源:发表于2017-07-31 18:16 被阅读25次

首先,你一定会创建好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;

等等。。。

相关文章

网友评论

      本文标题:iOS的tableViewCell自适应

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