UITableViewCell 的复用机制

cell重用机制

http://blog.cnrainbird.com/index.php/2012/03/20/guan_yu_uitableview_de_cell_fu_yong_tan_tan_wo_de_yi_xie_xin_de/

实现tableView的连个代理<UITableViewDelegate, UITableViewDataSource>即可,然后实现这两个代理的两个必要方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

这两个个方法,第一个是返回要显示的tableView中的cell的个数,第二个是为cell添加数据。其实根据cell的动态复用机制,就能推断出为cell添加数据的函数肯定是执行一次只能添加一个cell的。

 

 

原文地址:https://www.cnblogs.com/chaiwentao/p/4031766.html