Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove previous content from cell
    text
    copied!<p>I have tableview with searchbar. I am displaying number of data in cell. And I am creating cell using xib. I am also adding two button in cell. Now when I search anything in search bar at that time table is reloading and cell button are adding again on that place. See below screens shots: 1)First time created tableview:</p> <p><img src="https://i.stack.imgur.com/dAxQO.png" alt="enter image description here"></p> <p>2)After search data:</p> <pre><code>![enter image description here][2] </code></pre> <p><img src="https://i.stack.imgur.com/S0bge.png" alt="enter image description here"></p> <p>My code for This:</p> <pre><code>- (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; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload