1

We are developing an application in which we have to use Custom UItableViewcell to show data. While showing the data in UItableViewCell, if we are having any content(previously UItableViewCell already haviong content or bind with some data) in the UItableViewCell it needs to deleted and bind with new data otherwise the data needs to be bind to tableview. Below is the code that we have tried.

   if (cell.thumbnailImageView.image==nil) {             
         cell.thumbnailImageView.image = [imagearray objectAtIndex:indexPath.row];
         // cell.pricelabel.text = [pricearray objectAtIndex:indexPath.row];
         cell.DealDecLabel.text=[DealDecarray objectAtIndex:indexPath.row];

         cell.pricelabel.text = [NSString stringWithFormat:@"%@",[pricearray objectAtIndex:indexPath.row]];
     }
     else
     {
         cell.thumbnailImageView.image=nil;
         cell.DealDecLabel.text=nil;
         cell.pricelabel.text=nil;

         cell.thumbnailImageView.image = [imagearray objectAtIndex:indexPath.row];
         // cell.pricelabel.text = [pricearray objectAtIndex:indexPath.row];
         cell.DealDecLabel.text=[DealDecarray objectAtIndex:indexPath.row];

         cell.pricelabel.text = [NSString stringWithFormat:@"%@",[pricearray objectAtIndex:indexPath.row]];
     }

anyone provide solution or code is much appreciated.

4 Answers 4

2

This code is in cellForRowAtIndexPath right? If it's not it needs to be, but assuming it is

    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                          withRowAnimation:UITableViewRowAnimationNone];

will reload a specific cell in a tableView

    [self.tableView reloadData];

will reload the whole thing

You don't actually need to nil out the image each time either... you can simply do..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    MYCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell)
        cell = [[MYCustomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    cell.thumbnailImageView.image = [imagearray objectAtIndex:indexPath.row];
    cell.DealDecLabel.text=[DealDecarray objectAtIndex:indexPath.row];
    cell.pricelabel.text = [NSString stringWithFormat:@"%@",[pricearray objectAtIndex:indexPath.row]];


    return cell;

}

Potentially look at an array of dictionaries rather than 3 separate arrays..

and considering cell.imageView, cell.textLabel and cell.detailTextLabel are provided in a UITableViewCell subclass, I'd probably edit those to look like your two labels and delete them as they are unnecessary. The detailTextLabel needs UITableViewCellStyleDefault to be changed to UITableViewCellStyleSubtitle

0
1

if you are getting data from web services , then add below code.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"Did Finished loading....");
    // down here reload your tableview
    [self.tableView reloadData];
}
1
  • we are getting data based on other tableview cell is clicked then we are binding the data another tableview. Oct 21, 2014 at 13:15
0

Whenever you add new data into you array i.e in DealDecarray, just call

[self.tableView reloadData];

It will work for you.

0

Change the datasource of uitableview with new data and then reload the table.

[table reloadData];

2
  • we are getting data based on other tableview cell is clicked then we are binding the data another tableview. Oct 21, 2014 at 13:15
  • when you click on on one tableviewcell then at that time didselectrowatindex method call at that time change the datasource on another table. Oct 21, 2014 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.