UITableViewCell cellForRowAtIndexPath appeler grand nombre de lignes lors de la première de défilement

J'ai travaillé sur un problème relatif à la UITableView et cellForRowAtIndexPath.

Je veux donner à l'utilisateur la possibilité d'avoir un très grand nombre de lignes, un peu comme une grande liste d'e-mail sur iPhone. J'ai découvert ce problème quand j'ai commencé à créer une classe qui aurait et de file d'attente file d'attente des groupes d'enregistrements de la base de données, en tant que de besoin, afin d'économiser de la mémoire. J'ai constaté que lorsque mon UITableViewController des charges, il appelle ensuite cellForRowAtIndexPath pour la première 10 index (0 à 9). Le problème apparaît lorsque je cliquer sur ma souris sur le simulateur du noir à la surface externe de la zone ou je tente de faire défiler vers le bas sur la UITableView à l'aide d'un geste vers le haut. À ce stade, cellForRowAtIndexPath est appelée pour tous les autres indices. Cela se produit même si il y a+ de 1000 cellules. J'ai tenté de recréer un projet TRÈS SIMPLE avec seulement 100 index (rien de compliqué). Il fait exactement la même chose.. dès que j'ai défiler, il appelle cellForRowAtIndexPath de positions 10 à 99.

Est-ce le comportement normal d'un UITableView? Est-ce quelqu'un n'importe qui ont des idées de pourquoi il est inefficace à l'appel de toutes les lignes?

Je dirai que, une fois ce passage initial se produit, il semble que cela commence à fonctionner correctement. Je suis vraiment intrigué par ce parce qu'il est presque impossible de créer une classe pour les les d'attente et de file d'enregistrements en tant que de besoin.

Voici le code qui ma beaucoup plus simple exemple de projet:

//Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


//Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 return 100;
}


//Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


 printf("RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.row = %d\n", indexPath.row);


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

 cell.textLabel.text = @"Example Text";

 return cell;  
}

Console:

......
Chargement Initial de Vue
......

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 0

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.row = 1

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.row = 2

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.row = 3

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.row = 4

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.row = 5

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 6

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 7

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 8

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 9

......
Premier Geste De Défilement
......

ootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 11

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 12

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 13

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 14

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 15

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 16

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 17

.
.
J'ai enlevé un peu ici pour la raccourcir jusqu'
.
.

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 97

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 98

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 99

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 10

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 11

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 12

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 13

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 14

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 15

RootViewController, -tableView:cellForRowAtIndexPath; //indexPath.ligne = 16

(gdb)

Merci pour votre aide.

Eric

Modifier (jour suivant) --> aujourd'Hui, j'ai pensé à essayer un périphérique réel au lieu de mon simulateur. Mon iPhone 3GS ne pas reproduire ce comportement étrange. Je crois qu'il pourrait y avoir quelque chose de mal avec le simulateur sur ma machine. J'ai l'intention d'essayer un autre MAC quand le temps le permet.

OriginalL'auteur geekinit | 2010-10-27