Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to <code>nil</code> values you want to get rid off or insert repeatable code to reusability <code>if</code> (this is this: <code>if (cell == nil) {</code></p> <p>The major rule here is creating a cell you have to separate two kinds of object: - the objects unique to every cell (ex texts) - the repetitive objects (mainly style objects such as color, background, shadows, buttons and stuff)</p> <p>The first group should be outside reusability "if" <code>(cell == nil)</code>. The second one should be inside. </p> <p>In your case:</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]; 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]; [cell.contentView addSubview:doneButton]; [cell.contentView addSubview:previewButton]; } 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"]; [previewButton setTag:indexPath.row]; } 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"]; [previewButton setTag:indexPath.row]; } 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