tableviewcontrollerで大きなパフォーマンスの問題が発生しています。スクロールは非常に遅いです。didSelectRowAtIndexPathメソッドでNSLOGを作成しましたが、これはスクロールするたびに呼び出されることに気付きました。そんなはず?
このテーブルを検索しましたが、データはjsonの応答に依存するため、いくつかのロジックがあります。この方法はここで確認できます。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@" scroll");
// Configure the cell...
static NSString *CellIdentifier = @"contactCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];
UILabel *workPlaceLabel = (UILabel *)[cell viewWithTag:2];
if(searching)
{
//NSLog(@" copyListOfItems: %@",copyListOfItems);
NSString*lastName=[[[copyListOfItems objectAtIndex:indexPath.row]objectForKey:@"Contact"]objectForKey:@"lastname"];
if(lastName==nil)
{
lastName=@" ";
}
NSString*firstName=[[[copyListOfItems objectAtIndex:indexPath.row]objectForKey:@"Contact"]objectForKey:@"firstname"];
if(firstName==nil)
{
NSArray*phonesArray=[[[copyListOfItems objectAtIndex:indexPath.row]objectForKey:@"Contact"]objectForKey:@"phone"];
NSLog(@"NUMERO TELEFONE %d",[phonesArray count]);
if([phonesArray count]>0)
{
NSString*phoneNumber=[[[copyListOfItems objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Phone"];
nameLabel.text=phoneNumber;
}else{
nameLabel.text=[[[copyListOfItems objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Current"];
workPlaceLabel.text=@"";
}
}else{
NSString *stringName= [NSString stringWithFormat:@"%@ %@", firstName, lastName];
nameLabel.text=stringName;
workPlaceLabel.text=[[[copyListOfItems objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Current"];
}
}
else {
//NSLog(@" _contactsArray: %@",_contactsArray);
NSString*lastName=[[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Lastname"];
if(lastName==nil)
{
lastName=@" ";
}
NSString*firstName=[[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Firstname"];
if(firstName==nil)
{
NSArray*phonesArray=[[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Phone"];
//NSLog(@"NUMERO TELEFONE %d",[phonesArray count]);
if([phonesArray count]>0)
{
NSString*phoneNumber=[[[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"phone"] objectAtIndex:0]objectForKey:@"phonenumber"];
nameLabel.text=phoneNumber;
}else{
nameLabel.text=[[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Current"];
workPlaceLabel.text=@"";
}
}else{
NSString *stringName= [NSString stringWithFormat:@"%@ %@", firstName, lastName];
nameLabel.text=stringName;
if([[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Current"])
{
workPlaceLabel.text=[[[_contactsArray objectAtIndex:indexPath.row]objectForKey:@"Contact"] objectForKey:@"Current"];
}
}
}
// Configure the cell...
return cell;
}