indexPath does not match contents in tableView

0

I'm loading a tableView from a array loaded with arrays , this whole load process is working perfectly, however, when I update tableView ( reloadData ) with the same information and I have the scroll in the middle of the list, for example, the index's get lost, that is, when I access a cell, it loads information from another. On the other hand, if Scroll is at the top of tableView , even updating, this problem does not occur. Here is the code:

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

    static NSString *CellIdentifier = @"cell_aux";

    clsTableViewCell *cell = (clsTableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"cell_aux" owner:self options:nil];
        cell = (clsTableViewCell *)[nib objectAtIndex:0];
    }

    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

    arInfos = [[NSArray alloc] initWithArray:[[arMain objectAtIndex:indexPath.row]                  componentsSeparatedByString:@"|"]];

    [arInfosAll addObject:arInfos];

    NSURL *imgURL = [NSURL URLWithString:[arInfos objectAtIndex:4]];

    UIImage *Noimg=[UIImage imageNamed:@"NoImage.png"];
    cell.img.image = Noimg;


    cell.lblNome.text = [arInfos objectAtIndex:1];
    cell.lblEndereco.text =[arInfos objectAtIndex:2];

    NSURLRequest* request = [NSURLRequest requestWithURL:imgURL];
    [NSURLConnection sendAsynchronousRequest:request
                                           queue:[NSOperationQueue mainQueue]
                               completionHandler:^(NSURLResponse * response,
                                                   NSData *imgData,
                                                   NSError * error)
        {
                                   if (!error)
                                   {
                                       UIImage *img = [UIImage imageWithData:imgData];
                                       cell.img.image = img;
                                   }

                               }];
        }

    return cell;
}
    
asked by anonymous 03.09.2014 / 22:46

1 answer

1

I think the problem you are having is because of:     arInfos = [[NSArray alloc] initWithArray: [[arMain objectAtIndex: indexPath.row]

You point the arInfos to an array and then add it to arInfosAll The problem is that in the other interaction arInfos then points to another array, so it turns out that arInfosAll gets pointed to several arrays alike (the last to be assigned to ArInfos)

switch

arInfos = [[NSArray alloc] initWithArray:[[arMain objectAtIndex:indexPath.row]  

by

NSArray *arInfos = [[NSArray alloc] initWithArray:[[arMain objectAtIndex:indexPath.row]
    
17.09.2014 / 19:09