Reputation: 13178
I have a UITableView
which has images for all of the cells, but ALL of the images are already on the cell (i'm not setting the images my self) and they are all loaded from images included in the project. These are not images being loaded from a server or anything. However, the scrolling of the tableview is still some what jerky. Is there anything that can be done to speed it up? I have the function to generate the cell here:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Post init, update with the fair info so it can attend/de-attend on its own
CompaniesCustomCell *cell = [CompaniesCustomCell dequeOrCreateInTable:tableView];
SectionInfo *sectionInfo = [sectionInfoArray objectAtIndex:indexPath.section];
cell.fairDictionary = [sectionInfo.arrMDetails objectAtIndex:indexPath.row];
[cell updateEventIcon:(NSString*)[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"TYPE"]];
cell.lblFairName.text = [[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"TITLE"];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
// Set event start time, end time, and date
NSString *newDate = [MyUtil convertToLocalTime:@"MMMM dd, yyyy" :[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"START_TIME"]];
NSString *startString = [MyUtil convertToLocalTime:@"hh:mm a" :[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"START_TIME"]];
NSString *endString = [MyUtil convertToLocalTime:@"hh:mm a" :[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"END_TIME"]];
cell.lblFairDate.text = newDate;
cell.lblFairStartTime.text = startString;
cell.lblFairEndTime.text = endString;
return cell;
}
Is there anything I am doing wrong that could be slowing it down?
EDIT
I'm including the code for the convertToLocalTime
function here as I think this may be the root cause. However...I'm really confused how to optimize it. I'm taking the timestamp value from the server (in UTC) and I am converting that to the users local timezone. Is this process really that slow?
// Converts given time string into the users current timezone
// based on the location of their phone
+(NSString *)convertToLocalTime:(NSString*)format :(NSString*)stringDate {
// Get the date in the servers time zone
NSDate *date = [MyUtil convertToServerDate:stringDate];
// Convert the date to the local timezone
NSDateFormatter *localFormat = [[NSDateFormatter alloc] init];
[localFormat setDateFormat:format];
NSString *localDate = [localFormat stringFromDate:date];
[localFormat release];
return localDate;
}
// Provides a NSDate object with the servers timezone set
+(NSDate *)convertToServerDate:(NSString*)stringDate {
// First get the NSDate object in the servers timezone
NSTimeZone *tz = [NSTimeZone timeZoneWithName:ServerTimezone];
NSDateFormatter *inFormat = [[NSDateFormatter alloc] init];
[inFormat setDateFormat:@"yyyyMMddHHmmss"];
[inFormat setTimeZone:tz];
NSDate *date = [inFormat dateFromString:stringDate];
[inFormat release];
return date;
}
Upvotes: 1
Views: 887
Reputation: 1214
I've struggled with this issue quite a bit so I'm intimately aware of your problem. UITableView is jerky? I'm surprised all the answers are pointing to the date functions. You can take all that out and it will still be jerky.
Why? It's lazy image decompression. Even if all the images are from the app bundle, ios performs decompression at the moment it will be displayed on the screen. You have to manually decompress the images in a background thread.
Decompression does not merely mean instantiating a UIImage object. It can be somewhat complicated. The best solution, is to download SDWebImage and use the image decompressor that's included.
To read more about the issue see: http://www.cocoanetics.com/2011/10/avoiding-image-decompression-sickness/
Upvotes: 1
Reputation: 875
Like EarlyRiser said, check your date utility code. However, because it is class methods, you need to create new objects.
The other thing to try is to let the custom cell class change the labels. You can do this from when you set the fairDictionary. I assumed you used @property on fairDictionary in the .h of the custom cell.
In the .m of the custom cell overwrite the set method for fairDictionary so at the top in the @synthesize do:
@synthesize fairDictionary = _fairDictionary;
Then somewhere in the .m file call a method:
- (void)setFairDictionary:(NSDictionary *)fairDictionary {
_fairDictionary = fairDictionary;
[cell updateEventIcon:(NSString*)[_fairDictionary valueForKey:@"TYPE"];
self.lblFairName.text = [_fairDictionary valueForKey:@"TITLE"];
etc etc. So instead of the table datasource handling setting the title etc. The custom class will do it on setting the dictionary.
Hope this can help.
Upvotes: 2
Reputation: 736
I've done a fair amount of UITableView optimization recently and your best friend is the time profiler tool. If you don't know how to use it then you should learn, it's a life saver.
Here's a tutorial
One thing you might want to take a look at is your date utility code. What does it do inside it? Are you creating NSCalendar objects each time you call it? This can be enough to kill your performance. But real hard to know without profiling.
Upvotes: 1