iOS用SegmentController來切換tableView的時候 reloadData會造成資料重複建立 解決辦法
把在Cell上面建立的控制元件放在Cell==nil的判斷裡面,這樣,每次進來就會先判斷有沒有,就可以避免資料重複建立,導致檢視越蓋越厚
if (cell==nil) {
cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIDD];
self.inviteLabel=[[UILabelalloc]initWithFrame:CGRectMake(10,5,[UIScreenmainScreen].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
self.button.backgroundColor=[UIColorredColor];
[self.buttonsetBackgroundImage:[UIImageimageNamed:cell_info.cp] forState:UIControlStateNormal];
NSLog(@"cell_info.cp:%@",cell_info.cp);
//增加長按手勢
UILongPressGestureRecognizer *longPress=[[
[self.inviteLabel addGestureRecognizer:longPress];
longPress.minimumPressDuration=1.0;
[cell.contentView addSubview:self.button];
[cell.contentView addSubview:self.inviteLabel];
cell.backgroundColor=CELL_BACK_COLOR;
}