把在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;
}