I first display a table with contents of an array of strings. Later, i use another array of strings to display its contents. I set the text in the tableVIew:cellForRowAtIndexPath method as follows:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    NSString *string;
    if (condition)
    {
         string = array2[indexPath.row];
    }
    else
    {
         string = array1[indexPath.row];
    }

    NSLog(@"text:%@", string); // say, "house"
    cell.textLabel.text = string; //it is set correctly/as expected here, as verified by the log statement, but it shows the wrong text while displaying
    NSLog(@"text:%@", cell.textLabel.text); //same as value of variable string, "house", but it displays some other text, while it displays.

    return cell;
}

I also set the tableView:numberOfRowsInSection: as:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     if (condition)
     {
          return [array2 count];
     }
     else
     {
          return [array1 count];
     }

 }

Related posts

Recent Viewed