我使用搜索欄的tableview。我在單元格中顯示數據的數量。我正在用xib創建單元格。我還在單元格中添加了兩個按鈕。現在,當我在搜索欄中搜索任何內容時,表格正在重新加載,單元格按鈕在該地點再次添加。 見下面的屏幕截圖: 1)第一次創建實現代碼如下:如何從單元格中刪除以前的內容
2)搜索數據後:
![enter image description here][2]
我對這段代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
WorkDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WorkDetailCell"];
if (cell == nil) {
NSArray *topLevelObject;
topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"WorkDetailCell" owner:self options:nil];
cell = [topLevelObject objectAtIndex:0];
cell.backgroundColor=RGB(210, 200, 191);
cell.selectedBackgroundView=[self selectedCellView];
}
if(search==FALSE){
NSLog(@"%d",indexPath.row);
cell.clearsContextBeforeDrawing=YES;
//NSDictionary *detailList=[tempDataArray objectAtIndex:indexPath.row];
NSArray *temp=[tempDataArray objectAtIndex:indexPath.row];
cell.lblOrganization.text=[temp objectAtIndex:1];//@"TGB";//[detailList valueForKey:@"organizationName"];
cell.lblAddress.text=[temp objectAtIndex:2];//@"Ahmedabad";//detailList[@"address"];
cell.lblLandmark.text=[temp objectAtIndex:3];//@"SG HighWay";//detailList[@"landmark"];
cell.lblCity.text=[temp objectAtIndex:4];//@"Ahmedabad";//detailList[@"city"];
cell.lblState.text=[temp objectAtIndex:5];//@"Ahmedabad";//detailList[@"state"];
UIButton *doneButton=[UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame=CGRectMake(220, 45, 100, 60);
//[doneButton setTitle:@"pick" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(doneButtonClicked:) fo rControlEvents:UIControlEventTouchUpInside];
[doneButton setImage:[UIImage imageNamed:@"pick"] forState:UIControlStateNormal];
[doneButton setTag:indexPath.row];
UIButton *previewButton=[UIButton buttonWithType:UIButtonTypeCustom];
previewButton.frame=CGRectMake(235, 15, 65, 30);
[previewButton setTitle:@"Preview" forState:UIControlStateNormal];
[previewButton setTitleColor:RGB(110, 73, 44) forState:UIControlStateNormal];
[previewButton addTarget:self action:@selector(previewButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[previewButton setTag:indexPath.row];
[cell.contentView addSubview:doneButton];
[cell.contentView addSubview:previewButton];
}
else{
// NSDictionary *detailList=[searchResultArray objectAtIndex:indexPath.row];
// NSLog(@"dic%@",detailList);
//cell.contentView.clearsContextBeforeDrawing=YES;
cell.clearsContextBeforeDrawing=YES;
NSArray *temp=[searchResultArray objectAtIndex:indexPath.row];
cell.lblOrganization.text= [temp objectAtIndex:1]; //[detailList valueForKey:@"organizationName"];
cell.lblAddress.text=[temp objectAtIndex:2];//detailList[@"address"];
cell.lblLandmark.text=[temp objectAtIndex:3];//detailList[@"landmark"];
cell.lblCity.text=[temp objectAtIndex:4];//detailList[@"city"];
cell.lblState.text=[temp objectAtIndex:5];//detailList[@"state"];
UIButton *doneButton=[UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame=CGRectMake(220, 45, 100, 60);
//[doneButton setTitle:@"pick" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(doneButtonClicked:) fo rControlEvents:UIControlEventTouchUpInside];
[doneButton setImage:[UIImage imageNamed:@"pick"] forState:UIControlStateNormal];
[doneButton setTag:indexPath.row];
UIButton *previewButton=[UIButton buttonWithType:UIButtonTypeCustom];
previewButton.frame=CGRectMake(235, 15, 65, 30);
[previewButton setTitle:@"Preview" forState:UIControlStateNormal];
[previewButton setTitleColor:RGB(110, 73, 44) forState:UIControlStateNormal];
[previewButton addTarget:self action:@selector(previewButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[previewButton setTag:indexPath.row];
[cell.contentView addSubview:doneButton];
[cell.contentView addSubview:previewButton];
}
return cell;
確定我想要的是同樣的事情...謝謝you..and我得到你的觀點 – jayesh