iOS的tableViewCell自适应

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

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

iOS的tableViewCell自适应_第1张图片
如图1 。h文件中的声明

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

iOS的tableViewCell自适应_第2张图片
如图2.m文件中的计算方法

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

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

iOS的tableViewCell自适应_第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自适应)