UITableViewCell 的巧妙复用

来源:互联网 发布:网络剧制作播出许可证 编辑:程序博客网 时间:2024/06/05 22:35

做iOS很久了,可是毕竟碰到的问题还是有限的,今天就遇到了一个problem, 因为需要实现一个自己的SearchDisplayController, 想要加上一个dynamic cell for busy indicator,正考虑怎么给tableview加cell,是让SearchDispalyController继承UITableView,还是用代码+cellnib的方式动态加载,这两种方案都比较麻烦要写很多额外的code。


突然发现‘- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath’ 其实有个很有趣的地方,通常获取Cell

LoadingCell *cell = (LoadingCell *)[tableView dequeueReusableCellWithIdentifier:@"LoadingCellIdentifier" forIndexPath:indexPath];


那么如果不给searchResultTableView 注册cell那么就无法获得相应的cell,可是原tableViewController是有indicator cell的,那么怎么复用呢,原来很简单,只要写成

LoadingCell *cell = (LoadingCell *)[self.tableView dequeueReusableCellWithIdentifier:@"LoadingCellIdentifier" forIndexPath:indexPath]; 就OK了,self是searchDispplayController的contentViewController.

原来还可以这么用,又积累了一点!!Happy大笑

0 0
原创粉丝点击