I am working on a problem related to UITableView and cellForRowAtIndexPath.
I want to give the user the opportunity to have a very large number of lines, similar to a large list of letters on the iPhone. I discovered this problem when I started creating a class that, if necessary, backed up and deactivated groups of records from the database in order to save memory. I found that when my UITableViewController loads, it then calls cellForRowAtIndexPath for the typical first 10 indexes (0 to 9). The problem arises when I either click my mouse on the outside of the simulator screen or try to scroll down the UITableView using an upward gesture. At the moment, cellForRowAtIndexPath is called for all other indexes. This happens even if there are 1000+ cells. I tried to recreate a VERY SIMPLE project with only 100 indexes (nothing unusual). He does the same ... as soon as I scroll,it calls cellForRowAtIndexPath from positions 10 to 99.
Is this normal UITableView behavior? Does anyone have any idea why it is inefficiently invoking all lines?
I will say that as soon as this initial passage occurs, it seems that it begins to work correctly. I am really puzzled by this because it makes it almost impossible to create a class for queues and duty records as needed.
Here is the code in my much simpler project:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}
- (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:
...... bootstrap viewing ......
RootViewController, -tableView: cellForRowAtIndexPath; // indexPath.row = 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.row = 6
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 7
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 8
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 9
......
......
ootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 11
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 12
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 13
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 14
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 15
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 16
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 17
.
,
,
,
.
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 97
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 98
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 99
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 10
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 11
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 12
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 13
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 14
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 15
RootViewController, -tableView: cellForRowAtIndexPath;//indexPath.row = 16
(gdb)
.
( ) → . iPhone 3GS . , - . MAC, .