标签:ios reloaddata
把在Cell上面创建的控件放在Cell==nil的判断里面,这样,每次进来就会先判断有没有,就可以避免数据重复创建,导致视图越盖越厚
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIDD];
self.inviteLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,5,[UIScreen mainScreen].bounds.size.width-20,120)];
self.inviteLabel.numberOfLines=0;
self.inviteLabel.text=cell_info.title;
self.inviteLabel.textColor=LABEL_TEXTCOLOR;
int width=100;
int height=40;
self.button=[[UIButton alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-width/2,120+10, width, height)];
self.button.backgroundColor=[UIColor redColor];
[self.button setBackgroundImage:[UIImage imageNamed:cell_info.cp] forState:UIControlStateNormal];
NSLog(@"cell_info.cp:%@",cell_info.cp);
//增加长按手势
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[self.inviteLabel addGestureRecognizer:longPress];
longPress.minimumPressDuration=1.0;
[cell.contentView addSubview:self.button];
[cell.contentView addSubview:self.inviteLabel];
cell.backgroundColor=CELL_BACK_COLOR;
}
iOS用SegmentController来切换tableView的时候 reloadData会造成数据重复创建 解决办法
标签:ios reloaddata
原文地址:http://blog.csdn.net/darongzi1314/article/details/43271605