iOS开发 多个cell在初始化时注意重用池
2017-02-05 00:31
399 查看
多个cell在
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
方法中一定要分开来,用if或者switch,每一次上滑下拉都会调用这个方法,所以init初始化前面也必须加上
if (cell0 == nil)
来判断,不然会init多个cell
下面是一个实例-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0 && hadPublish) {
static NSString *cellIndentifier0 = @"headCell0";
HeadCurrent_View_Cell *cell0 = [tableView dequeueReusableCellWithIdentifier:cellIndentifier0];
if (cell0 == nil) {
cell0 = [[HeadCurrent_View_Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier0];
}
。。。。
return cell0;
}
else if (indexPath.section == 0 &&!hadPublish){
static NSString *cellIndentifier1 = @"headCellDefault";
UITableViewCell *cell0 = [tableView dequeueReusableCellWithIdentifier:cellIndentifier1];
if (cell0 == nil) {
cell0 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier1];
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
方法中一定要分开来,用if或者switch,每一次上滑下拉都会调用这个方法,所以init初始化前面也必须加上
if (cell0 == nil)
来判断,不然会init多个cell
下面是一个实例-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0 && hadPublish) {
static NSString *cellIndentifier0 = @"headCell0";
HeadCurrent_View_Cell *cell0 = [tableView dequeueReusableCellWithIdentifier:cellIndentifier0];
if (cell0 == nil) {
cell0 = [[HeadCurrent_View_Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier0];
}
。。。。
return cell0;
}
else if (indexPath.section == 0 &&!hadPublish){
static NSString *cellIndentifier1 = @"headCellDefault";
UITableViewCell *cell0 = [tableView dequeueReusableCellWithIdentifier:cellIndentifier1];
if (cell0 == nil) {
cell0 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier1];
。。。。
} cell0.selected = NO; cell0.selectionStyle = UITableViewCellSelectionStyleNone; return cell0; } static NSString *cellIndentifier = @"passengerOrderCell"; PassengerOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier]; if (cell == nil) { cell = [[PassengerOrderTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier]; } 。。。。 return cell; }
相关文章推荐
- IOS开发 UITableView中Cell重用机制导致内容重复解决方法
- 【10/27】 iOS开发成长之路,【cell重用】
- 【iOS开发-68】APP下载案例:利用tableView自带的cell布局+缓存池cell复用时注意按钮状态的检查
- iOS开发:开发过程中遇到的cell重用问题(其一)
- 【iOS开发-68】APP下载案例:利用tableView自带的cell布局+缓存池cell复用时注意button状态的检查
- ios开发基础1---UITableView中cell重用导致内容出错
- IOS开发之因Cell重用导致控件的状态级联改变
- 记一个iOS开发中cell的重用机制引发的错误
- ios开发 UITableCell 可重用问题
- iOS开发之关于cell的重用机制
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- iOS开发,tableView中cell的重用详解
- IOS Swift语言开发 tableView的重用以及自cell的自适应高度
- iOS开发-简述UITableView中cell的重用问题
- IOS开发: 返回字符串高度, 重定义cell高度, cell重用方法
- iOS开发之Cell重用机制理解
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- IOS Swift语言开发 tableView的重用以及自cell的自适应高度
- ios开发 UITableCell 可重用问题
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结