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=[[UIButtonalloc]initWithFrame:CGRectMake([UIScreenmainScreen].bounds.size.width/2-width/2,120+10, width, height)];
self.button.backgroundColor=[UIColorredColor];
[self.buttonsetBackgroundImage:[UIImageimageNamed:cell_info.cp]forState:UIControlStateNormal];
NSLog(@"cell_info.cp:%@",cell_info.cp);
//增加長按手勢
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPress:)];
[self.inviteLabeladdGestureRecognizer:longPress];
longPress.minimumPressDuration=1.0;
[cell.contentViewaddSubview:self.button];
[cell.contentViewaddSubview:self.inviteLabel];
cell.backgroundColor=CELL_BACK_COLOR;
}