i use a table view with custom values and image.
Every rows do this:
– Check device (iphone/ipad)
– Parse a wordpress xml
– Split this string “Thu, 13 Jan 2011 22:26:27 +0000” and get pos[1] and pos[2].
– Convert “Jan” in “Gennaio”
– set values in row cell
It’s make in this way:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@try {
newsRow = ((NewsRowController *)[tableView dequeueReusableCellWithIdentifier:@"cell"]);
if (newsRow == nil) {
if ( [[Device GetModel] isEqualToString:@"iPad Simulator"] || [[Device GetModel] isEqualToString:@"iPad"])
[[NSBundle mainBundle] loadNibNamed:@"NewsRow_ipad" owner:self options:nil];
else [[NSBundle mainBundle] loadNibNamed:@"NewsRow" owner:self options:nil];
if ([tableArray count] > 0) {
NSArray *chunks = [[dataArray objectAtIndex:indexPath.row] componentsSeparatedByString: @" "];
[newsRow setCellDataWithName:[tableArray objectAtIndex:indexPath.row]
andDate:[descArray objectAtIndex:indexPath.row]
day:[chunks objectAtIndex:1]
month:[self convertMonthToExtended:[chunks objectAtIndex:2]]];
}
}
}
@catch (NSException * e) {
NSLog(@"OK, crashato. Sappiamo il perchè!");
}
return newsRow;
}
the function convertMonthToExtended do this:
if ([small isEqualToString:@"Jan"]) return @"gennaio";
[...]
if ([small isEqualToString:@"Dec"]) return @"dicembre";
Now, on simulator it works very fine, but on device, a 3G device in particular, when i scroll the table it scroll slowly because i do a lot of things.
How can i speed up the scroll?
What is correct way to re-implement this function to be more fast?
How can i optimize this snippet?
Any idea please?
thanks,
A
I think that you can move the following code:
Outside the tableView:cellForRowAtIndexPath: method because you don’t need to do this check for every row (the device doesn’t change from line to line). And you can put this code in
viewDidLoad.I suggest you do all the computations and the work of asynchronous network.
You can precomputare all the information you need to populate the rows and save them in such a NSArray while viewing a UIProgressView or something like that, only after all the operations populate the table view.
You can use the
[Tableview reloadData]method to reload all data in the table view, this mean thatnumberOfSectionsInTableView:,tableView:numberOfRowsInSection:, and all the data source method are recalled.