0
I’m carrying a tableView
from a array
laden with arrays
, this whole charging process is working perfectly, however, when I update the 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 one cell, it loads information from another. On the other hand, if the Scroll is at the top of the tableView
, even updating, this problem does not occur. Follow 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;
}
Why are you doing this
[arInfosAll addObject:arInfos];
? One more question, why don’t you use Nsdictionary for each input of your array instead of another array?– Jan Cássio
Actually I could use Nsdictionary actually, but I ended up clicking on an array, because the content that fills it, was a string delimited by "|" Pipes, so I used arInfos = [[[Nsarray alloc] initWithArray:[[arrayAux objectAtIndex:indexPath.Row] componentsSeparatedByString:@"|"]]; The Usage [arInfosAll addObject:arInfos] is to store each array, as I will use it further. But it can influence this problem I’m facing?
– Silvio Vaz
One of your problems eh q arInfos eh uma Ivar. try to define and allocate it within the cellForRowAtIndexPath. ou seja, troque o arInfos = [[NSArray alloc] initWithArray:[[arMain objectAtIndex:indexPath.row] por NSArray *arInfos = [[NSArray alloc] initWithArray:[[arMain objectAtIndex:indexPath.row]
– CCastro
Hello, Thank you so much for the return! I made the recommended changes, but if I think there must be some other problem, as it has not yet worked, unfortunately. I also ran a test without "sendAsynchronousRequest" and the problem persisted.
– Silvio Vaz